You are given an m x n grid heights, where heights[r][c] is the elevation of cell (r, c).
A drop of water is placed at a starting cell start = (sr, sc). From a cell, water may flow to any of its 4-directional neighbors (up/down/left/right) only if the neighbor has strictly lower height than the current cell.
A cell is considered wet if water can reach it by repeatedly flowing according to the rule above (including the start cell).
Return the list (or set) of all wet cells.
heights
: 2D integer array of size
m x n
start
: two integers
(sr, sc)
with
0 <= sr < m
,
0 <= sc < n
(r, c)
that become wet.
m, n
can be up to a few thousand (so your approach should be near-linear in grid size in the worst case).