Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

root =
k =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

In-order traversal of a BST yields values in sorted order.

Approach

Iterative in-order traversal with a stack. Decrement k when visiting each node; when k==0, return that value.

Why it works

The k-th visited node in in-order is the k-th smallest.

Code
Loading...
Complexity
Time: O(h + k)
Space: O(h)
Solution
Updated: 2026-02-23

Idea

In-order traversal of a BST yields values in sorted order.

Approach

Iterative in-order traversal with a stack. Decrement k when visiting each node; when k==0, return that value.

Why it works

The k-th visited node in in-order is the k-th smallest.

Code
Loading...
Complexity
Time: O(h + k)
Space: O(h)