EASY DFS SOLUTION | BEATS 100% SOLUTION  | JAVA | PYTHON | C++
Upvote if you like quick and simple explanations!\n\nIntuition\nInitially we have the first row/column are able to reach the pacific ocean.\nSay our current loc
**Upvote** if you like quick and simple explanations!\n\n**Intuition**\nInitially we have the first row/column are able to reach the pacific ocean.\nSay our current location can reach the pacific, all locations with a height >= the current location can have water flow into our current location and thus reach the pacific.\n\nWe keep this principle and do a DFS over all nodes starting from the ones that can reach the pacific to find all nodes that can reach the pacific ocean if water were placed on it.\nWe do the exact same process for the atlantic ocean and then we check which positions can reach both the atlantic and pacific.\n\n**Note:** for simplicity we can say the sea is at water level (i.e height of 0)\n\n**SOLUTION**\n```java\nclass Solution {\n    public List<List<Integer>> pacificAtlantic(int[][] heights) {\n        \n        int rlen = heights.length;\n        int clen = heights[0].length;\n        \n        List<List<Integer>> output = new ArrayList();\n        boolean[][] atlantic = new boolean[rlen][clen];\n        boolean[][] pacific = new boolean[rlen][clen];\n\n\t\t//Do a DFS on all nodes at the pacific end and the atlantic end:\n        for(int r = 0; r < rlen; r++){\n            for(int c = 0; c < clen; c++){          \n                if(r == 0 || c == 0){ dfs(pacific, heights, r, c, 0);}\n                if(r == rlen-1 || c == clen-1){ dfs(atlantic, heights, r, c, 0); }\n            }\n        }\n        \n\t\t// Check which locations can reach both pacific and atlantic:\n        for(int r = 0; r < rlen; r++){\n            for(int c = 0; c < clen; c++){          \n                if(atlantic[r][c] && pacific[r][c]){\n                    output.add(Arrays.asList(r,c));\n                }\n            }\n        }\n        return output;\n    }\n    \n    // Go to a node - all the larger ones around it can reach the current sea:\n    public void dfs(boolean[][] sea, int[][] grid, int r, int c, int prev){\n        if(r < 0 || r >= grid.length || c < 0 || c >= grid[0].length) return;\n        if(grid[r][c] < prev) return;\n        if(sea[r][c]) return; \n        \n        sea[r][c] = true;\n        dfs(sea, grid, r+1, c, grid[r][c]); // bottom \n        dfs(sea, grid, r-1, c, grid[r][c]); // top \n        dfs(sea, grid, r, c-1, grid[r][c]); // left \n        dfs(sea, grid, r, c+1, grid[r][c]); // right\n    }\n}\n```\n\nI\'ll be back to making youtube videos on daily leetcode questions, come checkout the youtube channel here: \n**https://www.youtube.com/channel/UCfvW4KQXzpE3ZZqNxAHnaPQ**
['Depth-First Search', 'Java']