← Back to problems Solve on LeetCode → See #700 Search BST →

Kth Smallest in BST

LeetCode 230 • Medium • Trees

Input: root = [3,1,4,null,2], k = 3  →  Output: 3
Inorder traversal visits nodes in sorted order. Return the k-th visited value.

TimeO(h + k)push left chain + k pops
SpaceO(h)stack depth
Stack: []Count: 0
Current
In Stack
Visited (inorder)
Stack
[]
Count
0
Ready
Press Play. Iterative inorder: push left chain, pop and count. When count == k, return node.val.