Apple Interview Question

How would you code a solution