Problem of the day
You are given a Binary Search Tree.
Find the minimum value in it.
All the values in the given binary search tree are unique.
Input : 6 4 7 2 5 N N
Output: 2
Explanation:
For the given input BST is:
6
/ \
4 7
/ \
2 5
Minimum value in this tree is ‘2’.
The first line contains a string ‘T’ such that values in the string are in level order traversal of the tree, numbers denote the value of a node and character ‘N’ denotes a ‘NULL’ child.
For example, for the given BST :
4
/ \
2 5
/ \ / \
1 3 N N
Where N represents null child.
Input looks like following:
4 2 5 1 3 N N
Return the node with the minimum value. If tree is empty, return -1.
You don’t need to print anything, it has already been taken care of, just complete the given function.
8 5 N 3 6
3
BST for the given input looks like following:
8
/
5
/ \
3 6
Thus the minimum value in this BST is ‘3’.
5 3 6 2 4 N N
2
Try to do this in O(n), where 'n' is the number of nodes in the binary search tree.
0 <= ‘n’ <= 10^5
Time Limit: 1 sec
Where 'n' is the number of nodes in the binary tree.