Rain that reaches both seas
An island is a non-empty grid heights of integers. Sea A washes its top and left edges; sea B, its bottom and right edges. Rain on a cell flows to any neighbor up, down, left or right whose height is lower than or equal to its own, and from a cell on an edge it pours into the sea on that edge. Return every cell [r, c] whose rain can reach both seas, in any order.
Besides the tests, one large input (a 40 × 40 island) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
drains_to_both([[1,2,3],[2,4,2],[3,2,1]])→[[0,2],[1,1],[2,0]]drains_to_both([[3,3,3],[3,1,3],[3,3,3]])→[[0,0],[0,1],[0,2],[1,0],[1,2],[2,0],[2,1],[2,2]]drains_to_both([[1,1],[1,1]])→[[0,0],[0,1],[1,0],[1,1]]