Zendesk interview question

Can you write a working code for these algorithmic challenges?