Close
Topic list
Kth smallest node in BST
MEDIUM
15 mins
Binary Search Trees
Topics (Covered in this problem)
Problem solved
Skill meter
Binary Search Trees
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Kth smallest node in BST

Medium
0/80
Avg time to solve 15 mins
Success Rate 80 %
Share

## Problem Statement

#### You have been given a Binary Search Tree of integers. You are supposed to return the k-th (1-indexed) smallest element in the tree.

##### For example:
``````For the given binary search tree and k = 3
``````

``````The 3rd smallest node is highlighted in yellow colour.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````3
3
10 5 15 4 7 14 16 -1 -1 -1 -1 -1 -1 -1 -1
1
2 1 3 -1 -1 -1 -1
2
4 -3 5 -1 -1 -1 -1
``````
##### Sample Output 1:
``````7
1
4
``````
##### Explanation of Sample Input 1:
`````` For the first test case,
``````

``````The third-smallest node is 7.

For the second test case, the smallest node is 1.

For the third test case, the second-smallest node is 4.
``````
##### Sample Input 2:
``````2
2
-2 -4 1 -5 -1 -1 -1 -1 -1
3
10 8 11 -1 -1 -1 -1 -1 -1 -1 -1
``````
##### Sample Output 2:
``````-4
11
``````
##### Explanation of Sample Input 2:
``````For the first test case, the second-smallest node is -4.

For the second test case, the third-smallest node is 11.
``````
Auto
Console