Amazon Interview Question

Tree based Leetcode quesiton, probably easy or medium.