Google Interview Question

Dynamic Programing on first interview Trees in the second