The problem. Given the root of a binary search tree and a number k (1-indexed), return the k-th smallest value in the tree.
root = [3, 1, 4, null, 2], k = 1 -> 1
root = [5, 3, 6, 2, 4, null, null, 1], k = 3 -> 3Members only · free account
The rest of this lesson, with 6 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson