In-order Successor of Binary Search Tree

Given a binary search tree node, write a method to find its in-order successor.

Statement

Write a method to find the in-order successor of a BST node with a given value. Return -1 if the node with the given value does not exist.

The in-order successor of a node in a BST is the node with the smallest key greater than the key of the current node. This is the same as the next node in an in-order traversal of the BST.

Example

Consider the following BST:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.