Reported October 2026
Googleshortest path

Minimum Union of Two Routes

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

The detail that trips people in this Google problem is the phrase "distinct undirected edges in the union." Shared road gets counted once, and that changes everything. This one was reported in October 2026, and it's a shortest-path problem dressed up as a two-traveler puzzle. Alice starts at a, Bob at b, both end at d, and you minimize total edges used. If your invite says Google and you're due in a day or two, learn the meeting-point trick below. StealthCoder sits invisibly on your screen as a safety net if you blank during the live OA.

The problem

You are given an undirected, unweighted graph with n vertices numbered from 0 to n - 1. Alice starts at vertex a, Bob starts at vertex b, and both must reach destination d.
Alice chooses one path from a to d, and Bob chooses one path from b to d. The cost of their two routes is the number of distinct undirected edges that appear in the union of both paths.
Return the minimum possible cost. Return -1 when either traveler cannot reach d.

Examples
Example 1
n = 7
edges = [[0,2],[1,2],[2,3],[3,6],[0,4],[1,4],[4,5],[5,6]]
a = 0
b = 1
d = 6
return = 4
The travelers can meet at vertex 2. The edges from 0 and 1 to 2 contribute two edges, and the shared suffix 2 - 3 - 6 contributes two more.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: the two routes split before they merge, then share one suffix to d. So pick a meeting vertex m. Cost is dist(a,m) + dist(b,m) + dist(m,d). Run three BFS passes, from a, from b, and from d, since the graph is unweighted and undirected. Then loop over every vertex m reachable from all three and take the minimum sum. If a or b can't reach d, return -1. The pitfall is summing dist(a,d) + dist(b,d), which double counts shared edges. Another is forgetting that m can equal a, b, or d itself. In the example, meeting at vertex 2 gives 1 + 1 + 2 = 4. Complexity is O(n + E). If you freeze on why the meeting point works, StealthCoder is the hedge on the live OA, reading the problem and handing you the three-BFS structure.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Minimum Union of Two Routes cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Union of Two Routes FAQ

What's the trick in Minimum Union of Two Routes?+

Pick a meeting vertex m where the paths merge. Total cost is dist(a,m) + dist(b,m) + dist(m,d). Compute all three with BFS and minimize over every m. Shared edges after the merge get counted once, which is exactly what the union cost asks for.

Why can't I just add shortest paths from a and b to d?+

Because overlapping edges would be counted twice. The cost counts distinct edges in the union. If both paths use the same stretch to d, you pay for it once. The meeting-point formula models that shared suffix correctly.

Do I need Dijkstra for this?+

No. The graph is unweighted, so plain BFS gives shortest distances. Run it from a, b, and d. Since edges are undirected, distance from d to m equals distance from m to d, so three runs cover everything.

What edge cases should I test?+

Test when a or b can't reach d, which returns -1. Test a equal to b, where the best meeting point is a itself. Test m equal to d, where the paths only merge at the end. Also check disconnected components and unreachable vertices when looping candidates.

How do I prepare for this in 48 hours?+

Write BFS shortest distance on an adjacency list until it's automatic. Then practice the idea of combining distances from several sources through a middle vertex. This problem is that idea plus a min loop. Code it once end to end and check the example gives 4.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it