Problem: Minimum Height Trees Task: Given a tree with nodes, return all nodes that, when chosen as root, minimize the height of the tree. The answer is the center (or centers) of the tree.
You need to find the middle of the longest path. Use the "peeling the onion" algorithm: repeatedly remove leaves until only or nodes remain. Each round, you strip every current leaf and reduce the tree. The nodes left at the end are the centers. This runs in time and space.