Google Interview Question

Leetcode hard, a novel tree problem.