Back to course home
0% completed
Vote For New Content
Kth Smallest Element in a BST (medium)
Problem Statement
Given the root of a binary search tree (BST) and an integer k, return the k-th smallest value in the tree.
The values in the BST are unique.
. Examples
Example 1:
- Input: root =
[5, 3, 8, 2, 4, 7, 9, 1], k =3
5
/ \
3 8
/ \ / \
2 4 7 9
/
1
- Expected Output:
3 - Justification: The sorted order of the elements is
[1, 2, 3, 4, 5, 7, 8, 9]. The 3rd smallest value is3.
Example 2:
- Input: root =
[6, 4, 8, 2, 5, 7, 9, 1, 3], k =5
6
/ \
4 8
/\ / \
.....
.....
.....
Like the course? Get enrolled and start learning!