Challenge: Find the Minimum Value in a Binary Search Tree

Given the root to a binary search tree, write a function to find the minimum value in that tree. A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first.

Problem Statement

In this problem, you have to implement the findMin() function to find the minimum value in a given Binary Search Tree. A Binary Search Tree is a Binary Tree which satisfies the following property:

An illustration is also provided for your understanding.

NodeValues(LeftSubtree)<=CurrentNodeValue<NodeValues(RightSubTree)NodeValues(LeftSubtree)<=CurrentNodeValue<NodeValues(RightSubTree)

Function Prototype

int findMin(Node root);

Here, root is the root node of a Binary Search Tree

Output

It returns the minimum integer value from the given Binary Search Tree

Sample Input

bst = {
		6 -> 4,9
    4 -> 2,5
    9 -> 8,12
    12 -> 10,14
}
where parent -> leftChild,rightChild

Sample Output

2

Explanation

The minimum value in the above Binary Search Tree is 2. Here’s an illustration of the given challenge:

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