Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Graph problems

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Graph problems

Pacific Atlantic Water Flow

advancedlayer I5 · Graph problems5 tests

A rectangular island is described by heights, a grid of cell elevations. The Pacific ocean touches the island's top and left edges; the Atlantic touches its bottom and right edges.

Rain falling on a cell can flow to a neighbour (up, down, left or right) whose height is less than or equal to the current cell's height. Return every coordinate [row, col] from which water can reach both oceans.

  • Coordinates may be returned in any order
  • An empty grid returns an empty array

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen