Google interview question

Trees and dynamic programming. It was leetcode medium