Pregunta de entrevista de Amazon

two coding questions, one for dynamic programming, one for greedy