In-order Successor Binary Search Tree With Parent Pointers

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

Statement

Write a method to find the in-order successor of a given BST node using parent pointers. 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

In the following BST, each node has a parent pointer.

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