MEDIUMasked at 6 companies

Pacific Atlantic Water Flow

A medium-tier problem at 58% community acceptance, tagged with Array, Depth-First Search, Breadth-First Search. Reported in interviews at Nutanix and 5 others.

Founder's read

You're looking at a medium-difficulty matrix traversal problem that shows up in Amazon and Google onsite assessments. Pacific Atlantic Water Flow asks you to find every cell in a grid where water can flow to both coasts. The trap: most candidates think forward (water flowing out) when they should think backward (water flowing in). With a 57% acceptance rate, this one punishes the obvious approach. If you haven't drilled the reverse-flow pattern and hit this live, StealthCoder surfaces the working DFS or BFS solution invisible to the proctor.

Companies asking
6
Difficulty
MEDIUM
Acceptance
58%

Companies that ask "Pacific Atlantic Water Flow"

If this hits your live OA

Pacific Atlantic Water Flow 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. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The insight is counterintuitive. Instead of simulating water flowing from each cell outward (expensive, complicated), you run DFS or BFS backward from both ocean edges inward, marking which cells can reach the Pacific and which can reach the Atlantic. A cell qualifies if it's reachable from both. The algorithm leverages the matrix and graph-search topics to avoid redundant work. Common failure: attempting forward simulation from every cell, which leads to timeout or incorrect logic. Candidates who've only drilled standard DFS/BFS on grids often miss that the problem inverts the direction. If you blank on the reversal trick during your live assessment, StealthCoder runs invisibly and delivers the correct solution.

Pattern tags

The honest play

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

Pacific Atlantic Water Flow 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. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Pacific Atlantic Water Flow interview FAQ

Is Pacific Atlantic Water Flow still asked at FAANG in 2024?+

Yes. Amazon, Google, and TikTok all report asking it. It's a stable middle-tier problem in their matrix and search rotation. The 57% acceptance rate suggests it's not trivial, but it's not a rare curveball either.

What's the trick that makes this problem hard?+

Most candidates simulate water flowing outward from each cell. The faster approach reverses it: run DFS or BFS inward from both coasts and mark reachable cells. This cuts the work dramatically. The trick is recognizing that backward exploration is simpler than forward.

Do I need to know both DFS and BFS to solve this?+

No. Either works. DFS is more common in interviews because it's slightly shorter to code. BFS works identically and is cleaner if you prefer queue-based traversal. Pick whichever you're faster with.

How does this relate to other matrix problems I should know?+

Pacific Atlantic combines Array, Matrix, and Depth-First Search. If you're strong on island count, number of enclaves, or flood fill, you have the DFS muscles. This problem adds the inversion step, which is the new piece.

What companies ask this besides Amazon and Google?+

ServiceNow, Nutanix, Coupang, and TikTok all report it. It's not exclusive to mega-cap tech. Mid-tier and infrastructure companies ask it too, so it's worth drilling regardless of target company.

Want the actual problem statement? View "Pacific Atlantic Water Flow" 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.