shlogg · Early preview
Md Ariful Haque @mah-shamim

Minimum Height Trees Roots [1,3,4]

Find minimum height trees (MHTs) by performing two-pass BFS: build graph, find leaf nodes, trim leaves until only 1 or 2 nodes remain. These are MHT roots.

310. Minimum Height Trees
Difficulty: Medium
Topics: Depth-First Search, Breadth-First Search, Graph, Topological Sort
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.
Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges where edges[i] = [ai, bi] indicates that there is an undirected edge between the two nodes ai and bi in the tree, you can choose any node of the tree as the root. When you select a node x as the root, the result tree has height h. Among all po...