Uber interview question

Medium leetcode difficulty. Something to do with bst