MEDIUMasked at 4 companies

Minimum Height Trees

A medium-tier problem at 42% community acceptance, tagged with Depth-First Search, Breadth-First Search, Graph. Reported in interviews at Stackline and 3 others.

Founder's read

Minimum Height Trees hits hard because the naive approach kills you. You think "root the tree at every node and pick the one with minimum height," and you'll time out on large graphs. Stackline, Splunk, Citadel, and PhonePe all ask this one. The acceptance rate sits at 42%, which means half the room either sees the pattern or doesn't. The trick isn't depth-first search or breadth-first search alone. It's knowing when to stop searching and recognizing that only 1-2 nodes will ever be optimal. If you blank on that insight during your OA, StealthCoder surfaces the working solution in seconds, invisible to the proctor.

Companies asking
4
Difficulty
MEDIUM
Acceptance
42%

Companies that ask "Minimum Height Trees"

If this hits your live OA

Minimum Height Trees 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 FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.

Get StealthCoder
What this means

The insight is that the minimum height tree must be rooted at or near the center of the graph. A naive DFS from every node is O(n squared), which won't pass. Instead, think topologically: peel away the leaves layer by layer, like an onion. BFS from all leaf nodes simultaneously, removing them and their edges each round, narrows down the candidates until one or two nodes remain. Those are your answers. The pattern is counterintuitive because it looks like you're doing less work, not more. Most candidates waste time coding the brute force. If you don't see the leaf-stripping pattern under pressure, StealthCoder handles the implementation while you stay undetected.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Minimum Height Trees 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 FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Height Trees interview FAQ

Why does the naive DFS approach fail?+

You'd compute the height by rooting at each of n nodes. That's O(n squared) in the worst case on a dense graph, which exceeds time limits. The problem expects you to find the center in O(n) or O(n log n). The topological peeling approach does it in linear time by eliminating leaves in layers.

Is BFS really better than DFS here?+

Not inherently. BFS works well for the leaf-peeling strategy because you process all nodes at the same depth simultaneously. DFS can solve it too, but you'd still need the topological insight. The data structure (queue vs stack) matters less than recognizing you need to find the graph's center, not its height from every root.

Can there be more than two minimum height trees?+

No. The answer is always 1 or 2 nodes. If two exist, they must be adjacent. This constraint is baked into the problem and helps you terminate early. Most candidates overthink the multi-answer case and waste lines on unnecessary bookkeeping.

How does topological sort connect?+

Topological sort deals with dependency ordering in DAGs. Here, you use a topological concept: remove all current leaves, then the next leaves emerge. It's not a classical topological sort, but the idea of processing nodes by their incoming edge count is analogous. Recognizing that link separates solvers from TLE submissions.

Do companies still ask this after LeetCode published the solution?+

Yes. Stackline, Splunk, Citadel, and PhonePe all reported it recently. The acceptance rate is 42%, not 90%, because many candidates either bomb it live or time out. It's not a rare problem, which means prep matters. If you haven't internalized the peeling pattern, your OA becomes a coin flip.

Want the actual problem statement? View "Minimum Height Trees" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.