MEDIUMasked at 7 companies

Shortest Bridge

A medium-tier problem at 59% community acceptance, tagged with Array, Depth-First Search, Breadth-First Search. Reported in interviews at McKinsey and 6 others.

Founder's read

Shortest Bridge shows up in assessments at Uber, TikTok, Snap, and Flipkart, and it trips up candidates who can't see the two-phase structure. You're given a matrix with exactly two islands of 1s, and you need to find the minimum number of 0s you'd flip to connect them. The trick isn't obvious: most candidates waste time trying a single pass when the problem demands you isolate one island first, then measure the distance to the other. It's a medium-difficulty problem with a 59% acceptance rate, which means about half the people who attempt it get stuck. StealthCoder solves it invisibly during your OA if the two-phase insight doesn't click.

Companies asking
7
Difficulty
MEDIUM
Acceptance
59%

Companies that ask "Shortest Bridge"

If this hits your live OA

Shortest Bridge 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The pattern is DFS plus BFS, not just one or the other. First, use DFS to mark every cell in one island. Then BFS from all marked cells simultaneously to find the shortest path to any cell in the second island. The trap is thinking you can check both islands in a single traversal, or that a greedy distance metric will work. Most failed attempts try to calculate Euclidean or Manhattan distance directly, missing that the actual shortest flip-path might snake around obstacles. The acceptance rate sits at 59% because candidates either understand the two-phase approach immediately or they flounder for 15 minutes rewriting flawed single-pass logic. StealthCoder lets you skip the flounder and land a working solution in seconds, even if you didn't drill the island-isolation pattern.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Shortest Bridge recycles across companies for a reason. It's medium-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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shortest Bridge interview FAQ

Why can't I just find the closest pair of cells from each island?+

Because the shortest path between two cells in a grid isn't always their straight-line distance. You must account for the actual grid topology and obstacles. BFS from all marked cells explores all valid neighbors simultaneously, guaranteeing the shortest flip-sequence. Greedy distance fails on grids.

Is Shortest Bridge still asked frequently at big companies?+

Yes. It appears in reports from Uber, TikTok, Snap, Flipkart, and others. Medium-difficulty island problems remain common filters. The 59% acceptance rate confirms it's hard enough to distinguish strong candidates but not obscure.

What's the most common mistake on this problem?+

Trying to solve it in one pass. Candidates attempt BFS or DFS on both islands at once and get tangled logic. The solution requires explicit two-phase thinking: phase one identifies and marks island A, phase two spreads BFS from A until it touches island B. Separation of concerns matters.

How does this differ from standard island-counting problems?+

Island count just labels connected components. Shortest Bridge adds a distance metric and requires you to find the minimum cost path between two specific components. You're moving from 'identify' to 'measure and connect,' which is why DFS alone won't cut it; BFS becomes mandatory.

Can I solve this with just Array and Matrix operations, or do I need the graph patterns?+

You need the graph patterns. DFS and BFS are the core algorithmic tools here. While the input is a 2D array, the problem is fundamentally about traversing connected components and computing shortest paths, which are graph concepts. Treating it as pure array manipulation will stall you.

Want the actual problem statement? View "Shortest Bridge" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.