Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 310 Minimum Height Trees - Problem Statement

Finding centroids

Find the root(s) that reduce tree height. There are at most 22 such roots, and they're the tree's centroid(s). Approach 11: Root at each node, compute height, take minimum. O(n2)O(n^2) naive, O(n)O(n) with rerooting.

Approach 22: Peel leaves layer by layer. Remove all degree-11 nodes, repeat. The last 11-22 nodes remaining are the answer. Both approaches give the centroid(s). The peeling approach is simpler and naturally handles the "at most 22" property.