Pocket Gems interview question

Algorithm, big O