Search⌘ K
AI Features

Pacific Atlantic Water Flow

Explore the Pacific Atlantic Water Flow challenge by learning to identify cells on a grid where rainwater can reach both oceans. Understand how to apply matrix traversal techniques and height comparisons to solve this problem effectively, enhancing your problem-solving skills in coding interviews.

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 (m×n)(m \times n). Here, heights[r][c] represents the elevation of the cell at coordinate (r,c)(r, c).

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 99 ...