Home
Topics
Practice
Roadmap
DSA Tracker
Code Editor
Tech Blogs
More
Sign in
Get started
Loading question...
Feedback
Minimum Height Trees
Medium
00:00
0 users online
Share
Description
Solution
Submissions
Discussion
Given a tree with n nodes, find all root labels of Minimum Height Trees.
Sample Input:
4, [[1,0],[1,2],[1,3]]
Sample Output:
[1]
Hints
Hint 1
MHT roots are centroids of the tree
Hint 2
Trim leaves layer by layer until ≤ 2 nodes remain
Hint 3
Use BFS from all leaves simultaneously
Code Editor
Reset
Run
Save
Loading...