HackerRank interview question

A DP problem and a binary tree problem