I recognized it was related to the Pacific Atlantic problem pretty fast, which helped.
Model the grid as a directed graph where edges point from higher/equal cells to lower/equal cells, then run a multi-source BFS/DFS from all starting points to find all reachable cells. Alternatively, reverse the flow direction and propagate from boundary cells inward, but since starting points are given, forward propagation is more direct. Use a queue for BFS to efficiently explore all reachable cells.
Pro tip: Clarify with the interviewer whether water can flow to equal-height cells (yes, per problem) and whether starting points are guaranteed to be inside the grid. Also, consider using a visited set to avoid cycles and ensure O(m*n) time complexity.
Confirm the flow rule (to adjacent cells with height <= current), the grid dimensions, and that starting points are given. Ask about edge cases like multiple starting points, equal heights, and whether water can flow out of the grid.
Recognize this as a graph traversal problem. Since we need all cells reachable from multiple sources, a multi-source BFS or DFS is appropriate. BFS is often preferred for shortest path but here any traversal works; BFS with a queue is straightforward.
Initialize a queue with all starting points and a visited set. While the queue is not empty, pop a cell, mark it as wet, and for each of its 4 neighbors, if the neighbor's height <= current cell's height and not visited, add it to the queue.
After traversal, the visited set contains all wet cells. Return them as a list of coordinates or a boolean grid, depending on the required output format.
Time complexity is O(m*n) since each cell is visited at most once. Space complexity is O(m*n) for the queue and visited set. Test with edge cases: single cell, all equal heights, starting points on boundaries, and disconnected regions.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.