dsa8 min read
Pacific Atlantic Water Flow — Reverse DFS from Two Oceans (LC 417)
Find every cell from which water can flow to both oceans by reversing the flow and running DFS inward from each ocean. The reverse-flow trick that turns an O(N^4) brute force into O(N^2).
Read →