Clean python code O(mn) - DFS
Naive solution is to do DFS from every other point and see if it reaches both the ocean but the trick to optimisation is to start from the oceans itself and go 
Naive solution is to do DFS from every other point and see if it reaches both the ocean but the trick to optimisation is to start from the oceans itself and go backwards to every point. Visited ones are all the points that are reachable from ocean so in the end, intersection of points `visited by pacific` and `visited by atlantic` will give you the answer.\n\nAnother thing to note is that the checks always start from the first and last rows/columns for each iteration. For columns, we iterate over each one and keep the row at 0 and m-1 while for rows we keep the column as 0 and n-1 for pacific and atlantic respectively.\n\n```\nclass Solution:\n\n    def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:\n        m, n = len(heights), len(heights[0])\n        v_pac = set()\n        v_atl = set()\n        \n        def dfs(v_set, row, col, curr_height):\n            if row < 0 or row >= m or \\\n                col < 0 or col >= n or \\\n                    (row,col) in v_set or \\\n                        curr_height > heights[row][col]:\n                return\n            v_set.add((row, col))\n\n            curr_height = heights[row][col]\n            dfs(v_set, row + 1, col, curr_height)\n            dfs(v_set, row - 1, col, curr_height)\n            dfs(v_set, row, col + 1, curr_height)\n            dfs(v_set, row, col - 1, curr_height)\n\n        # Approach is to start from both sides of \n        # the oceans and then reach each point that can be \n        # reached while maintaining the visited indices\n\n        # Iterate over columns and start from both 0, m-1 rows\n        for col in range(n):\n            dfs(v_pac, 0, col, heights[0][col]) # First row\n            dfs(v_atl, m - 1, col, heights[m-1][col]) # Last row\n\n        # Iterate over rows and start from both 0, n-1 cols\n        for row in range(m):\n            dfs(v_pac, row, 0, heights[row][0]) # First column\n            dfs(v_atl, row, n-1, heights[row][n-1]) # Last column\n\n        # Co-ordinates which can reach both the oceans are the winners\n        # so we take intersection\n        result = v_atl.intersection(v_pac)\n\n        return result\n```
['Depth-First Search', 'Python', 'Python3']