Kth Smallest Element in a BST
Given the root of a binary search tree represented as an array in level-order and an integer `k`, return the `k`-th smallest value (1-indexed) of all the values of the nodes in the tree. **Examples:** ```typescript kthSmallest([3, 1, 4, null, 2], 1) // 1 kthSmallest([5, 3, 6, 2, 4, null, null, 1], 3) // 3 ```
Solve It in the BrowserPractice Explaining It Out Loud
Optimal Approach
- Time complexity: O(H + k)
- Space complexity: O(H)
In-order traversal visits nodes in ascending order, stopping at the k-th node.
Follow-Up Questions Interviewers Ask About Kth Smallest Element in a BST
- How would you optimize this if the BST is modified often and kth-smallest queried frequently?
Augment each BST node with a subtree_size counter, allowing O(H) lookup directly without traversal.
Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.