Pregunta de entrevista de Bloomberg

Question about tree implementation, and a dp problem