Apple Interview Question

Algorithm design