medium
Kth Smallest Element in a BST
Given the root of a binary search tree and an integer k, return the k-th smallest value stored in the tree (1-indexed).
Constraints
- 1 ≤ n ≤ 10^4
- 1 ≤ k ≤ n
- 0 ≤ node value ≤ 10^4
Examples
in: root = [3,1,4,null,2], k = 1
out: 1
in: root = [5,3,6,2,4,null,null,1], k = 3
out: 3
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.