Inorder Successor in BST
Medium · Binary Search Trees · about 15 minutes
Asked at Meta, Microsoft, Amazon, Google, Bloomberg.
The binary search tree has distinct values, and p is the value of one of its nodes. Return the next larger value in the tree after p (the node visited right after it in an in-order walk), or -1 when p is the largest.