Python [DFS / Beats 99.13%] with full working explanation
\nclass Solution:\n    def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:  # Time: O(mn) and Space: O(mn)\n       \n\t    rows, cols = len(
```\nclass Solution:\n    def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:  # Time: O(mn) and Space: O(mn)\n       \n\t    rows, cols = len(heights), len(heights[0])\n        pac, atl = set(), set()\n\n        def dfs(r, c, visit, prevHeight):  # current location, set of already visited tiles, the value of the tile where we are calling the dfs function\n          \n\t\t    # we will check if the index[r, c] is not already visited, row and column is inbounds and\n            # the current tile should be lower than from we are coming from, it\'s the condition for waterflow mentioned\n            # if any one of these conditions fails exit the dfs by returning to from we came from\n            if (r, c) in visit or r < 0 or c < 0 or r == rows or c == cols or heights[r][c] < prevHeight:\n                return\n\t\t\t\t\n            visit.add((r, c))  # mark the tile visited(pac or atl depending on what is passed from the dfs function) when the if conditions true\n\t\t\t\n            dfs(r + 1, c, visit, heights[r][c])  # we will next visit the tile down from the current one\n            dfs(r - 1, c, visit, heights[r][c])  # up\n            dfs(r, c + 1, visit, heights[r][c])  # right\n            dfs(r, c - 1, visit, heights[r][c])  # left\n\n        for c in range(cols):                            # we will traverse the first & last row by fixing the r and moving c\n            dfs(0, c, pac, heights[0][c])                # first row is just next to pacific\n            dfs(rows - 1, c, atl, heights[rows - 1][c])  # last row is just next to atlantic\n\n        for r in range(rows):                            # we will traverse the first & last column by fixing the c and moving r\n            dfs(r, 0, pac, heights[r][0])                # first column is just next to pacific\n            dfs(r, cols - 1, atl, heights[r][cols - 1])  # last column is just next to atlantic\n\n        return list(pac.intersection(atl))  # returns the list which contains the same [i, j] in both the sets\n```
['Depth-First Search', 'Python', 'Python3']