Pacific Atlantic Water Flow
Learn to solve the Pacific Atlantic Water Flow challenge by analyzing a matrix representing island elevations. Discover how to determine cells where water flows to both oceans, applying problem-solving patterns useful in coding interviews and improving your algorithmic skills.
We'll cover the following...
Statement
Imagine an island with a rectangular shape that touches both the Pacific and Atlantic oceans. The northern and western sides meet the Pacific, while the southern and eastern sides touch the Atlantic. This island is divided into square cells.
To depict the height above sea level of each cell, we use an integer matrix, heights, of size . Here, heights[r][c] represents the elevation of the cell at coordinate .
When heavy rain pours down on the island every few months, water flows from the island to both the Pacific and Atlantic oceans. The path of flow depends on the heights of the cells.
Consider a cell with a height of ...