Kth Smallest Element in a BST
A medium-tier problem at 75% community acceptance, tagged with Tree, Depth-First Search, Binary Search Tree. Reported in interviews at Agoda and 6 others.
Kth Smallest Element in a BST is a medium-difficulty tree problem that shows up across FAANG and scale-ups like Agoda, Oracle, Google, Cisco, Meta, TikTok, and Uber. The premise is straightforward: given a BST and an integer k, return the kth smallest value. The trap is thinking you need to build a sorted array or run a full traversal every time. 75% of candidates pass, but most waste time on the wrong approach. If this problem hits your live OA and the tree structure throws you, StealthCoder surfaces the optimal solution invisible to the proctor.
Companies that ask "Kth Smallest Element in a BST"
Kth Smallest Element in a BST is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe key insight is in-order traversal. A BST walked in-order yields elements in ascending sequence, so the kth node you visit is your answer. The obvious failure mode is building a full sorted list, which burns space and time. Instead, use DFS with a counter. Walk left, increment when you hit a node, and return early once the counter equals k. This costs O(k) time in the best case (balanced tree) and O(n) worst case (skewed), but it's clean and passes every test. The second approach is to cache tree heights and jump directly to the kth node using BST properties, but that's overkill unless the OA demands repeated queries. If you blank on the pattern during the live assessment, StealthCoder runs the in-order DFS solution in seconds.
Pattern tags
You know the problem.
Make sure you actually pass it.
Kth Smallest Element in a BST recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Kth Smallest Element in a BST interview FAQ
Is this really asked at Google, Meta, and Uber?+
Yes. It's in active rotation at all seven companies listed. It's not a leetcode-hard filter, but it's a reliable signal test for tree intuition and whether you can spot the in-order traversal pattern under pressure.
What's the trick I'm missing?+
In-order DFS. Walk the tree left-to-right, increment a counter at each node, and return the value when counter equals k. Most people overthink it and build a sorted array first, wasting space and time.
Does a 75% acceptance rate mean it's easy?+
Not quite. It means most people who attempt it pass, but that includes those who've drilled tree traversals. Cold OA takers often struggle because the in-order insight isn't obvious without tree interview prep.
What if the tree is unbalanced or huge?+
In-order DFS still works. Worst case is O(n) time if k is large or the tree is skewed, but you exit early and don't store anything. For repeated queries on a static tree, cache node subtree sizes and binary-search the kth value instead.
Is this related to other BST problems?+
Yes. It combines Tree, Binary Search Tree, and Depth-First Search. If you're solid on in-order traversal and BST properties, you'll also pass kth largest, rank queries, and range-sum BST problems. It's a foundation pattern.
Want the actual problem statement? View "Kth Smallest Element in a BST" on LeetCode →