Apple interview question

Design an algorithm