Reorder Routes to Make All Paths Lead to the City Zero
CodingOASoftware EngineerReported Jan, 2026
Examples
Example 1:
Input: n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]
Output: 3
Example 1:
Input: n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]
Output: 3
There are n cities labeled from 0 to n - 1 and n - 1 directed roads that form a tree.
Return the minimum number of edges that must be reversed so every city can reach city 0.
2 <= n <= 5 * 10^4connections.length == n - 1connections[i].length == 2Reported as LeetCode 1466 in a software engineer OA.