Wish interview question

leetcode 844 and a medium tree problem