Pregunta de entrevista de Amazon

Technical question was Greedy minimization problem