Minimum Height Trees
A tree is an undirected graph in which any two vertices are connected by exactly one path. Find all Minimum Height Trees (MHTs) and return the roots of those MHTs. Use a graph peeling technique (BFS).
Why Interviewers Ask This
Salesforce interviewers ask this to evaluate your ability to optimize graph traversal beyond standard BFS. They specifically test if you recognize that the center of a tree minimizes height, rather than brute-forcing every node. This assesses your skill in identifying edge cases, understanding topological sorting properties, and writing efficient O(N) solutions under pressure.
How to Answer This Question
Key Points to Cover
- Recognizing that the solution requires finding the graph center, not just any path
- Implementing the topological sort peeling technique for O(N) efficiency
- Handling edge cases like single nodes or disconnected components correctly
- Explaining why removing leaves layer-by-layer guarantees the minimum height
- Demonstrating clear communication of the iterative reduction process
Sample Answer
Common Mistakes to Avoid
- Running BFS from every node individually, leading to unnecessary O(N^2) time complexity
- Failing to handle the edge case where the input contains only one or two nodes
- Using DFS instead of BFS/Topological Sort, which complicates the layer-peeling logic
- Not explaining why the last remaining nodes are guaranteed to be the optimal roots
Practice This Question with AI
Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.