Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find Minimum in BST

Easy Acceptance 85.18% Points 20.00

You are given the root of a Binary Search Tree (BST). Your task is to find and return the minimum value stored in the tree.

Return the smallest value present in the BST.

Examples
Example 1

image Input: root = [5,3,8,1,4,null,9]
Output: 1
Explanation: The leftmost node holds the smallest value, which is 1.

Example 2

image Input: root = [10,null,20]
Output: 10
Explanation: The root has no left subtree, so the root itself is the minimum.

Example 3

image Input: root = [42]
Output: 42
Explanation: A single-node BST has its minimum equal to the root value.

Hints
Hint 1
In a BST:
Hint 2
  • Every node in the left subtree has a smaller value than the current node.
Hint 3
  • Therefore, the leftmost node always contains the minimum value in the tree.
Constraints
    • 1 = Number of nodes = 104
    • -10? = Node.data = 10?
Companies
PhonePe Paytm
Topics
Tree Traversal Binary Tree
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions