Pocket Gems interview question

Greedy related algorithm question