Simulate Water Flow
Problem Overview
- Simulate rainfall on a 2D elevation grid where water moves to adjacent cells of equal or lower height.
- From startRow, startCol, return a grid of the first time step each cell gets wet (0 at start, -1 if never).
- Input: integer matrix and start coordinates; Output: same-size timestamp matrix; scalable to large grids.
- Real-world domain: civil engineering and digital elevation models.
- From Uber interviews: a coding interview problem and common interview question.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
