Trains the technique from
LeetCode 417Pacific Atlantic Water FlowThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A flat roof is paved with square tiles laid out in a rows x cols grid. levels[r][c] is the height of the tile in row r, column c.
Rain that lands on a tile spreads to any tile sharing an edge with it whose height is the same or lower, and keeps spreading from there under the same rule. Two gutters collect the runoff:
0 or column 0 is collected there;rows - 1 or column cols - 1 is collected there.A tile is twin-draining when rain landing on it can reach the front gutter and can also reach the back gutter. Return the coordinates [r, c] of every twin-draining tile. The coordinates may be listed in any order.
Example 1
Tile [1, 1] stands at height 5. Water runs from it to [0, 1] at height 2, which lies in the top row and so reaches the front gutter, and it runs to [2, 1] and on to [3, 1], which lies in the bottom row and so reaches the back gutter.
Example 2
Tile [1, 2] lies in the right column, and water runs from it to [0, 2] in the top row, so both gutters are reached. Tile [0, 0] lies in the top row, but both of its neighbours stand higher, so no water leaves it and the back gutter stays out of reach.
Example 3
From tile [1, 1] at height 3 the only tiles at the same height or lower are [0, 1] in the top row and [2, 1] in the bottom row, so both gutters are reached.
Example 4
The single tile lies in the top row and in the bottom row at once.
The values you return may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def pacific_atlantic(levels: list[list[int]]) -> list[list[int]]:public List<List<Integer>> pacificAtlantic(int[][] levels)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.