Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Kth Smallest Element in BST

Medium Acceptance 76.77% Points 30

You are given the root of a Binary Search Tree (BST) and an integer k. Your task is to return the kth smallest element in the BST.

Examples
Example 1

image Input: root = [3,1,4,null,2], k = 1
Output: 1
Explanation: The smallest element in the BST is 1.

Example 2

image Input: root = [5,3,6,2,4,null,null,1], k = 3
Output: 3
Explanation: The elements in sorted order are 1, 2, 3, 4, 5, 6, so the 3rd smallest element is 3.

Example 3

image Input: root = [2,1,3], k = 2
Output: 2
Explanation: The 2nd smallest element in the BST is 2.

Constraints
    • 1 = Number of nodes = 105
    • -10? = Node.data = 10?
    • 1 = k = Number of nodes
Topics
Tree Traversal Binary Tree
Companies
Expedia Morgan Stanly
Added 08 Aug 2026 76.77% acceptance
Ln 1, Col 1Sign in to save your code
50 30 70 20 40 60 80
3
40