JAVA Easy Beginner Friendly Simple DFS calls with checks Slow but Works Fine.
\nclass Solution {\n    List<List<Integer>> res;\n    public List<List<Integer>> pacificAtlantic(int[][] heights) {\n        res = new ArrayList<>();\n        f
```\nclass Solution {\n    List<List<Integer>> res;\n    public List<List<Integer>> pacificAtlantic(int[][] heights) {\n        res = new ArrayList<>();\n        for(int i = 0;i<heights.length;i++){\n            for(int j=0;j<heights[0].length;j++){\n                if((i==heights.length-1 && j==0) || (i==0 && j==heights[0].length-1)){\n                    res.add(Arrays.asList(i,j));\n                    continue;\n                }\n                boolean[] pair = new boolean[2];\n                boolean[][] visited = new boolean[heights.length][heights[0].length];\n                dfs(heights,i,j,pair,visited,heights[i][j]);\n                if(pair[0] && pair[1]) res.add(Arrays.asList(i,j));\n            }\n        }\n        return res;\n    }\n    public void dfs(int[][] heights,int i,int j,boolean[] pair,boolean[][] visited,int prev){\n        if(i<0 || j<0 || i>=heights.length || j>=heights[0].length || visited[i][j] == true || heights[i][j] > prev) return;\n        if(i == 0 || j==0) pair[0] = true;\n        if(i == heights.length-1 || j == heights[0].length-1) pair[1] = true;\n        if(pair[0] && pair[1]) return;\n        prev = heights[i][j];\n        visited[i][j] = true;\n        dfs(heights,i-1,j,pair,visited,prev);\n        dfs(heights,i,j+1,pair,visited,prev);\n        dfs(heights,i+1,j,pair,visited,prev);\n        dfs(heights,i,j-1,pair,visited,prev);\n    }\n}\n```
['Depth-First Search', 'Java']