Skip to content
Discussion options

You must be logged in to vote

We need to determine which cells in a given grid can allow rainwater to flow to both the Pacific and Atlantic oceans. The Pacific Ocean borders the top and left edges of the grid, while the Atlantic Ocean borders the bottom and right edges. Water can flow from a cell to neighboring cells in the four cardinal directions if the neighboring cell's height is less than or equal to the current cell's height.

Approach

  1. Problem Analysis: The problem requires identifying cells from which water can flow to both oceans. Directly checking each cell would be inefficient due to the grid size (up to 200x200). Instead, we use a reverse traversal approach starting from the ocean borders.
  2. Key Insight: Wate…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Oct 5, 2025
Maintainer Author

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Oct 5, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants