Given an array of size **N** which represents the elements to be inserted into **BST** (considering first element as root). The task is to find the minimum element in this given BST. If the tree is empty, there is no minimum elemnt, so print **-1** in that case.

**Input:**

The input line contains **T**, denoting the number of testcases. Each testcase contains two lines. The first line contains **N** (number of nodes in BST). The second line contains N nodes of the BST separated by space.

**Output:**

For each testcase in new line, print the minimum element in BST.

**User Task:**

The task is to complete the function **minValue()** which takes root as the argument and returns the minimum element of BST.

**Constraints:**

1 <= T <= 100

1 <= N <= 100

**Example:
Input:**

2

6

5 4 3 6 7 1

3

9 10 11

**Output:**

1

9

**Explanation:
Testcase 1: **We construct the following BST by inserting given values one by one in an empty BST.

5

/ \

4 6

/ \

3 7

/

1

The minimum value in the given BST is 1.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

preparecodinginterview_dot_com | 190 |

__murugan__ | 173 |

manvimahajan20 | 140 |

xiaoyan_yunche | 139 |

ShameekAgarwal | 116 |

preparecodinginterview_dot_com | 190 |

__murugan__ | 173 |

manvimahajan20 | 166 |

SoumyaKaushik | 146 |

arpit_anshuman | 140 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.