Apple interview question

Code Problem