Reported September 2026
Googlememoization

Trace Every Water Drop to Its Resting Destination

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's September 2026 OA reportedly hands you a grid where every cell is a water drop, and an off-grid neighbor counts as height 0. That one detail flips the problem. A drop on a positive cell can slide right off the edge, and negative cells can trap it. The pattern is memoized descent on a functional graph: each cell points to exactly one next cell or stays put. If you simulate every drop separately, you'll blow past 100000 cells. If you blank on the structure, StealthCoder is the safety net running invisibly during the live OA.

The problem

You are given an m x n integer matrix heights. Place one drop of water on every cell. A drop repeatedly considers the four orthogonally adjacent positions and moves to the position with the lowest height, but only when that height is strictly lower than its current cell.
A position immediately outside the grid has height 0. If a drop moves to such a position, it has left the grid and stops there. When several lowest positions have the same height, choose the one with the lexicographically smallest coordinate: compare the row first, then the column.
Return an array containing one [row, column] destination for every source cell in row-major order. A destination inside the grid is the cell where the drop can no longer descend. An outside destination is the one-step-outside coordinate where the drop leaves the grid, so its row may be -1 or m, or its column may be -1 or n.

Function
waterDestinations(heights: int[][]) → int[][]

Examples
Example 1
heights = [[5,4,5],[4,-1,4],[5,4,5]]
return = [[-1,0],[1,1],[-1,2],[1,1],[1,1],[1,1],[2,-1],[1,1],[2,3]]
The four edge-center cells descend into the basin at [1,1], as does the basin itself. Each positive corner sees two equally low outside positions of height 0 and uses the lexicographically smaller coordinate.
Example 2
heights = [[5]]
return = [[-1,0]]
All four adjacent positions are outside with height 0. Coordinate [-1,0] is lexicographically smallest.
Example 3
heights = [[0,0],[0,0]]
return = [[0,0],[0,1],[1,0],[1,1]]
Every adjacent position, including each outside position, has height 0. Because a move must be strictly downhill, every drop remains on its source cell.

Constraints
1 <= m, n.
m * n <= 100000.
-10^9 <= heights[row][column] <= 10^9.
Every move is to one of the four orthogonally adjacent positions.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Each cell has at most one outgoing move: the strictly lower neighbor with the lowest height, ties broken by smallest row, then smallest column. That makes the grid a functional graph with no cycles, because heights strictly decrease along every move. So you compute each cell's destination once and reuse it. Sort cells by height ascending and process them in that order. When you reach a cell, its next target is already resolved, so dest[cell] = dest[next], or the cell itself if no move exists. Outside positions are terminal with height 0, and their coordinates are the one-step-outside ones like [-1,c] or [r,n]. The classic pitfall is the tie-break. Compare height first, then row, then column, and include outside neighbors in that comparison. Another trap is recursion depth on 100000 cells, so go iterative. If the tie logic tangles live, StealthCoder is the hedge when you freeze.

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 Trace Every Water Drop to Its Resting Destination 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.

Trace Every Water Drop to Its Resting Destination FAQ

What's the trick to the Google water drop problem?+

Every cell has exactly one next move, and heights strictly decrease, so there are no cycles. Resolve each cell's destination once and reuse it. Process cells from lowest height to highest, or use memoized DFS, so nothing gets simulated twice.

How do I handle the outside-the-grid positions?+

Treat any neighbor outside the grid as height 0 with its own coordinate, like [-1,c], [m,c], [r,-1], or [r,n]. Include them in the min comparison with the same tie-break. If an outside spot wins, that's the destination and the drop stops.

How does the tie-break work?+

Among neighbors, pick the lowest height. If heights match, pick the smaller row, then the smaller column. Outside coordinates compete too. For a [[5]] grid all four neighbors are 0, and [-1,0] wins as the lexicographically smallest.

Will plain simulation pass the constraints?+

Risky. A long descending staircase makes each drop walk many steps, and with m*n up to 100000 that can go quadratic. Memoizing or processing in height order gets you O(mn log mn) for the sort, or O(mn) with DFS.

How do I prepare for this in 48 hours?+

Write the neighbor selection function first and test it on the three examples, especially the flat 0 grid where nothing moves. Then add the memo layer. Use an iterative approach to dodge recursion limits. Check negative heights too, since an outside 0 is higher than them.

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