Kth Smallest in BST

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start•← → to step•? all shortcuts

Solution Guide: Kth Smallest in BST

Approach

Inorder traversal of BST is sorted; return the k-th visited value.

Complexity Analysis

Time
O(h + k) average, O(n) worst
Space
O(h)

Pattern

Inorder Ranking

Why It Works

BST inorder order preserves ascending value sequence by definition.

Updated Mar 2026