Amazon interview question

Tree based Leetcode quesiton, probably easy or medium.