Google interview question

Leetcode hard, a novel tree problem.