Find Minimum and Maximum Elements

Concepts and Basic Operations DSA practice problem on Onlearn.

Difficulty: medium.

Topics: How do you find the minimum and maximum values in a Binary Search Tree (BST)?, Binary Search Tree, Binary Tree, Node, Traversal, Recursion, Iteration, Time Complexity, Space Complexity, iterative algorithms, complexity analysis, binary search tree, recursion, tree traversal.

Find Minimum and Maximum in a Binary Search Tree Problem Statement Given a sequence of integers, construct a Binary Search Tree (BST) by inserting them one by one. After constructing the BST, find and return the minimum and maximum values present in the tree. Input Specification The first line contains an integer N (1 <= N <= 10^5), the number of elements to insert. The second line contains N space separated integers val 1, val 2, ..., val N ( 10^9 <= val i <= 10^9), the values to be inserted into the BST. All values will be distinct. Output Specification Output two space separated integers: the minimum value and the maximum value found in the BST. Constraints 1 <= N <= 10^5 10^9 <= val i <= 10^9 All val i are distinct.