Product
Pricing
Blog
Forum
NEW
Referral
Description
Solution
Discussion
Submissions
Ask AI
AI Insights
Quick Summary
Find a root node in a directed tree that minimizes the number of edge reversals required to make all edges point away from it.
The input guarantees a tree structure with exactly n-1 directed edges connecting n nodes.
Evaluate every possible root choice and return the smallest reversal count.
What This Tests
Tree and graph traversal techniques
Rerooting dynamic programming concept
State propagation and incremental cost updates
Transforming directed graphs into weighted structures
Common Patterns
Graph Traversal
DFS/BFS
Dynamic Programming
Collapse
Hint 1
Hint 2
What Interviewers May Ask Next
Report
Report seen similar question in interview
Ask AI Assistant
Ask AI Assistant
Ask me anything about this coding question!
python
Auto
Debug
Run
Submit
Test Cases
Input
Output
Expected