15% off all plans & roadmaps Use code
See plansLeetCode 310 · Solution & editorial
A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.
Minimum Height Trees is a Graph Traversal Patterns (DFS & BFS) problem, in the Graph BFS - Topological Sort (Kahn's Algorithm) subpattern. The pattern covers DFS/BFS traversal, topological sort, shortest paths, Union-Find, and MST
Master topological sorting using Kahn's BFS algorithm. Solve course schedule and build order problems.
The reference solution runs in O(n) time and O(n) space.
Minimum Height Trees has been reported in interviews at Facebook.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Minimum Height Trees is a Graph Traversal Patterns (DFS & BFS) problem, in the Graph BFS - Topological Sort (Kahn's Algorithm) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.