Amazon interview question

Hard leet code greedy algorithm problem.