Minimum Edge Reversals So Every Node Is Reachable
A hard-tier problem at 55% community acceptance, tagged with Dynamic Programming, Depth-First Search, Breadth-First Search. Reported in interviews at MathWorks and 2 others.
You're given a directed graph where you need to make every node reachable from node 0 by reversing the minimum number of edges. It sounds straightforward until you realize the graph isn't necessarily connected to begin with, and reversing edges has a ripple effect across your traversal strategy. MathWorks, Microsoft, and Meesho have all asked this. With a 55% acceptance rate, candidates typically fall apart when they conflate "reversing an edge" with "adding a reverse edge," or they try to solve it greedily and hit a wall. If you blank on the pattern during your live OA, StealthCoder surfaces the working solution invisibly.
Companies that ask "Minimum Edge Reversals So Every Node Is Reachable"
Minimum Edge Reversals So Every Node Is Reachable is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe trick is to reframe the problem: instead of thinking about reversing edges in the original graph, build an undirected version where every edge has a cost. An edge that already points away from 0 costs 0 to traverse (you keep it); an edge pointing toward 0 costs 1 (you'd have to reverse it). Then run BFS or DFS from node 0 and sum the reversal costs. The pattern breaks because you're not doing a standard shortest-path search; you're doing a reachability sweep where the cost represents the minimum reversals needed to reach that subtree. Most candidates either miss the undirected trick entirely and try to modify the original graph in place, or they implement Dijkstra when a simple DFS with cost aggregation solves it. Dynamic Programming and Graph traversal both apply, but the graph-reframing insight is what separates solvers from blockers. StealthCoder is your safety net the moment you realize the greedy approach is leading you in circles.
Pattern tags
You know the problem.
Make sure you actually pass it.
Minimum Edge Reversals So Every Node Is Reachable recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Edge Reversals So Every Node Is Reachable interview FAQ
What's the actual difference between reversing an edge and adding a bidirectional edge?+
Reversing an edge means changing its direction. The trick here is to think of it as cost: if the original edge points away from node 0 (in your BFS direction), keep it at cost 0. If it points toward 0, you'd reverse it, so mark it cost 1. Build an undirected graph with these costs, then sum them during traversal.
Why doesn't a greedy 'always pick the cheapest edge' approach work?+
Because you're not looking for a minimum spanning tree or shortest path between two nodes. You're finding the minimum reversals to reach all reachable nodes from node 0. The cost aggregation depends on the traversal order and parent-child relationships in the BFS/DFS tree, not individual edge cost.
Is this problem still asked at FAANG despite the 55% acceptance rate?+
Yes. Microsoft and MathWorks have both reported this problem. The 55% rate suggests it's a legitimate hard problem, not an outlier. It tests both graph construction intuition and traversal fundamentals, which are core.
How does the Dynamic Programming topic fit here?+
The DP angle is subtle: as you traverse, you're building up the minimum cost to reach each node. Each node's reversal cost depends on the path taken from the root. It's DP in the sense that subproblem solutions (costs of subtrees) combine to form the final answer.
What's the most common mistake candidates make on this problem?+
Trying to modify the original directed graph in place or confusing 'reverse the edge' with 'add a reverse edge.' The key is reframing: build an undirected graph where each original edge has a direction-dependent cost, then do a standard traversal and sum costs.
Want the actual problem statement? View "Minimum Edge Reversals So Every Node Is Reachable" on LeetCode →