Pregunta de entrevista de Electrifex

2 dynamic programming questions, questions were quite difficult too.