Amazon interview question

greedy algorithm question