Problem context and objectives
Mission briefing
Archive pathfinder · Clues branch through a living archive
Explore only the branches that can still contain the answer: The Kth Grove.
Ignoring the parent-child rule turns a focused search into a full maze traversal.
How you win
- 1Recognize when Kth smallest in BST matches the clues
- 2Keep this true after every move: after each pop, exactly count smallest BST values have been visited in order
- 3Reach the result within O(height + k) time and O(height) space
Rules and pressure
- Target cost: O(height + k) time and O(height) space
- State rule: after each pop, exactly count smallest BST values have been visited in order
Lesson 1 of 3
Treat every pop as the next sorted rank and stop immediately at k. Lesson questions refer to the original tree and rank.
Connect the left spine, stack top, and rank counter in one scene.
Your call · With stack [5,3,2,1], which value is next in sorted order?