Google interview question

(1) tree/dynamic programming relating algorithm