Pick a cell in the center of the grid. Trace water flowing downhill from it. Eventually it reaches the Pacific border (top or left edge) and the Atlantic border (bottom or right edge). That cell is in the answer. Simple enough — until you realize you have to repeat this for EVERY cell.
I tried this first. I wrote a forward DFS from each cell and it worked on small grids. Then I submitted it. Time Limit Exceeded. I stared at the grid for fifteen minutes before the reversal clicked — and when it did, I felt genuinely annoyed at myself for not seeing it sooner. The answer was literally at the edges of the grid.
The problem: for each of the m*n cells, you launch a DFS that might traverse the entire grid — O(m*n) per cell. Multiply: O((m*n)^2). For a 200x200 grid (allowed in LC 417), that is 1,600,000,000 operations. The time limit is 2 seconds. You do the math.
The deeper problem is redundancy. The center cells are checked by dozens of starting points. Cell (2,2) gets visited by the DFS launched from (2,1), (2,3), (1,2), (3,2), AND every other cell that flows through it. The same traversal, over and over, slightly shifted each time.
Tap any non-border cell to trace water flowing downhill from it