Dashboard
LC #230
Kth Smallest Element in a BST
Pattern · ?AmazonBloombergGoogleMeta
Problem
Find the kth smallest element in a BST.
Constraints
- 1 ≤ k ≤ n ≤ 10⁴
- 0 ≤ node.val ≤ 10⁴
Example
- Input
- root = [3,1,4,null,2], k = 1
- Output
- 1
- Why
- In-order traversal gives [1, 2, 3, 4]. The 1st smallest is 1.
Spot the pattern
Which pattern cracks it?
Hints
One at a time