Minimum Height Trees
Signals to notice
Brute force first
Root the tree at each node, compute height, find minimum. That direct path helps you understand the question, but it tends to treat every possibility as brand new instead of learning from earlier steps.
The key insight
Topological peeling: repeatedly remove leaf nodes (degree 1) layer by layer, like peeling an onion. The last 1-2 nodes remaining are the centroids (minimum height tree roots). Instead of recomputing the world every time, you preserve just enough context to let the next decision become obvious.
What must stay true
The centroid(s) of a tree are the 1-2 nodes at the very center. Removing leaves brings you closer to the center. The process terminates with 1 or 2 remaining nodes. As long as that statement keeps holding, you can trust the steps built on top of it.
Easy way to go wrong
Not handling the case of exactly 2 remaining nodes — a tree can have 1 or 2 centroids. Both are valid answers. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.