Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find Maximum in BST

Easy Acceptance 85.54% Points 20

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

Return the largest value present in the BST.

Examples
Example 1

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

Example 2

image Input: root = [10,5]
Output: 10
Explanation: The root has no right subtree, so the root itself is the maximum.

Example 3

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

Constraints
    • 1 = Number of nodes = 104
    • -10? = Node.data = 10?
Hints
  • In a BST:
    • Every node in the right subtree has a greater value than the current node.
    • Therefore, the rightmost node always contains the maximum value in the tree.
Topics
Tree Traversal Binary Tree
Companies
Paytm Wipro
Added 08 Aug 2026 85.54% acceptance
Ln 1, Col 1Sign in to save your code
50 30 70 20 40 60 80
80