Uber interview question

Leetcode hard related to trees