Coding · should-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix
Kth Smallest Element in a BST
Problem
Given the root of a binary search tree and an integer k, return the k-th smallest value in the tree, counting from 1. All values are distinct and k never exceeds the number of nodes.
- The tree has between 1 and 50,000 nodes and is not necessarily balanced.
- Node values are distinct non-negative integers.
1 <= k <= number of nodes.
Examples
root = [12, 6, 20, 3, 9, 15, 30],k = 1→3. The smallest value is the leftmost node.root = [40, 25, 55, 18, 33, None, 70, None, 21],k = 3→25. Sorted order is 18, 21, 25, 33, 40, 55, 70.root = [9],k = 1→9.
Hints
- Which traversal order of a BST produces its values in sorted order?
- You do not need the whole sorted sequence, only the
k-th element. Can you stop early? - Iterative inorder with an explicit stack; pop
ktimes and return thek-th popped value.
Last reviewed 8 September 2026
Locked
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Secure payment by Stripe · instant access · refund questions: [email protected]
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.