Apple Interview Question

Mainly algorithms but it was a good one