Reported September 2026
Googledynamic programming

Shortest Round Trip Through All Deliveries

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

Google reported this one in September 2026, and it looks friendly until the edge cases show up. A grid, a courier, up to 9 deliveries, and a round trip back to S. The hinted pattern is simulation, but the real work is BFS plus a route search over the deliveries. If you've got an OA invite and you're scanning for the trick, it's this: don't walk the grid for every route. Compress it to a small distance graph first. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the idea fits in your head.

The problem

You are given a rectangular grid containing one start, open cells, obstacles, and delivery points:
S is the unique start.
D is a delivery point.
. is an open cell.
# is an obstacle.
From an open cell, the courier may move one cell up, down, left, or right at unit cost. The courier must start at S, visit every D at least once in any order, and return to S.
Return the minimum total travel distance. Return -1 when no such round trip exists. Only the distance is required, so equally short routes need no tie-breaker.

Function
shortestDeliveryRoundTrip(grid: String[]) → int

Examples
Example 1
grid = ["S.D","...","D.."]
return = 8
Each delivery is two steps from the start, and the two deliveries are four steps apart. Visiting them in either order and returning costs 2 + 4 + 2 = 8.
Example 2
grid = ["S..#","##.#","D..D"]
return = 14
The start-to-left-delivery distance is 6, the delivery-to-delivery distance is 3, and the right delivery is 5 steps from the start. The minimum round trip therefore costs 14.

Constraints
1 <= grid.length <= 30.
1 <= grid[i].length <= 30, and every row has the same length.
Each cell is S, D,., or #.
The grid contains exactly one S and from 1 through 9 cells marked D.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Run BFS from S and from each D, giving pairwise shortest distances on at most 10 nodes. Then it's a traveling salesman on 10 points. With 9 deliveries, bitmask DP works: dp[mask][last] is the minimum cost to visit the set mask and end at last. Close the loop by adding the distance from last back to S. The edge case that breaks naive solutions is unreachability. If any D can't be reached from S, return -1 immediately, and treat missing BFS distances as infinity, not zero. Another pitfall is greedy nearest-neighbor, which fails on example-style layouts where the closest delivery first costs more overall. Also don't assume a path can't pass through a D or S while heading elsewhere. Those cells are walkable. If the DP or bitmask indexing slips under pressure, StealthCoder is the hedge during the live OA, but practice the transition once and you're set.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Shortest Round Trip Through All Deliveries 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shortest Round Trip Through All Deliveries FAQ

What's the actual trick in the Google shortest round trip problem?+

Reduce the grid to a distance matrix between S and each D using BFS, then solve a traveling salesman style bitmask DP over the deliveries. With at most 9 deliveries, 2^9 times 9 states is tiny. The grid size only matters for the BFS step.

Why does greedy nearest-delivery fail here?+

Picking the closest next stop can force a long detour later and an expensive return to S. The cheapest round trip depends on the whole ordering, not local choices. That's why you need DP over subsets, or brute-force permutations, since 9 deliveries means 362,880 orders.

When do I return -1?+

Return -1 if any delivery point isn't reachable from S through open cells, since the round trip can't visit it. Since movement is undirected, reaching it from S also means returning. Check this right after the BFS runs, before starting the DP.

Can the courier walk through other D cells or back through S?+

Yes. D and S are walkable cells, only # blocks movement. Your BFS should treat S, D and. as open. Passing over a delivery on the way to another one is fine, and the DP handles it naturally through shortest distances.

How do I prepare for this in 48 hours?+

Write BFS on a grid from memory, then write a bitmask DP for a small TSP with a return to the start. Test it on the two examples, expecting 8 and 14. Then try a grid with an unreachable D to confirm you output -1.

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