Apple Interview Question

Hackerank question to complete in your own time.