17. Inorder Successor in BST
Given a binary search tree (See Definition) and a node in it, find the in-order successor of that node in the BST.
If the given node has no in-order successor in the tree, return null
.
It's guaranteed p is one node in the given tree. (You can directly compare the memory address to find p)
Example 1:
Example 2:
Solution: (Using Inorder Traversal)
Solution: (Properties of BST)
Approach: If value is less than root then, root can be the successor and we check for Left Tree Else we got to right subtree
Last updated