FreeCareerPath
Build the PrimitiveMedium

Kth Smallest Element in a BST

Write `kth_smallest(root, k)` returning the kth smallest value (1-indexed) in the BST. An in-order traversal of a BST visits values in ascending order, so this is "stop after k visits." Collecting every value into a list and indexing works and is O(n) — the better answer stops early, which matters when k is small and the tree is large.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Kth Smallest Element in a BST" are saved to your account — logging in takes a few seconds.

Kth Smallest Element in a BST — FreeCareerPath