Pergunta de entrevista da empresa Bloomberg

Question about tree implementation, and a dp problem