Pacific Atlantic Water Flow (LC #417) finds cells where water can reach both oceans. Instead of flowing from each cell, reverse the problem: start from ocean borders and flow uphill. Run DFS/BFS from all Pacific border cells, marking reachable cells. Do the same for Atlantic. Return cells marked in both sets. This runs in time and space. The reverse thinking is the trick. Meta tests if you can optimize by changing the problem direction.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/meta-interview-prep/graphs/pacific-atlantic-water-flow
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████████████████████████████████████