Apple interview question

Mainly algorithms but it was a good one