Java DFS Solution
\nclass Solution {\n    boolean pacific;\n    boolean atlantic;\n    int numRows;\n    int numColumns;\n    public List<List<Integer>> pacificAtlantic(int[][] m
```\nclass Solution {\n    boolean pacific;\n    boolean atlantic;\n    int numRows;\n    int numColumns;\n    public List<List<Integer>> pacificAtlantic(int[][] matrix) {\n        //Go through all the cells in the matrix\n        //Run a DFS for each cell\n        //In the execution of the DFS, set pacific and atlantic to true or false\n        //at the end of the execution, if both pacific and atlantic are true, then add i,j to the list\n        \n        //create a boolean visited matrix\n        \n       \n        //create a list of answers;\n        List<List<Integer>> answers = new ArrayList<List<Integer>>();\n        if(matrix == null || matrix.length == 0 || matrix[0].length == 0)\n            return answers;\n        \n        numRows = matrix.length;\n        numColumns = matrix[0].length;\n        \n        \n        for(int i = 0;i<matrix.length; i++)\n        {\n            for(int j = 0;j<matrix[0].length;j++)\n            {\n                pacific = false;\n                atlantic = false;\n                boolean[][] visited = new boolean[matrix.length][matrix[0].length];\n                dfs(matrix,visited,i,j);\n                if(pacific && atlantic)\n                {\n                    ArrayList<Integer> temp = new ArrayList<Integer>();\n                    temp.add(i);\n                    temp.add(j);\n                    answers.add(temp);\n                }\n            }\n        }\n        return answers;\n        \n        \n        \n    }\n    \n    //In the execution of DFS,\n    //once you set the value of pacific or atlantic to true, don\'t change it\n    public void dfs(int[][] matrix, boolean[][] visited, int i, int j)\n    {   \n        //mark the node as visited\n        visited[i][j] = true;\n        \n        //check for pacific\n        if(( ( (i==0) && (j>=0 && j<numColumns) ) || ( (j==0) && (i>=0 && i<numRows) ) ) && !pacific)\n        {\n           pacific = true; \n        }\n        \n        \n        //check for atlantic\n        if(( ( (i==numRows-1) && (j>=0 && j<numColumns) ) || ( (j == numColumns-1) && (i>=0 && i<numRows) ) ) && !atlantic)\n        {\n           atlantic = true; \n        }\n        \n        // if(i<0 || i>=numRows || y<0 || y>=numColumns )\n        //     return;\n        \n        int x = i;\n        int y = j;\n        //top is x-1,y\n            if( (x-1)>=0 && y>=0 && y<numColumns && (matrix[x][y] >= matrix[x-1][y]) && !visited[x-1][y])\n                dfs(matrix,visited,x-1,y);\n        \n        \n        //right is x,y+1\n         if( x>=0 && x<numRows && y+1<numColumns && (matrix[x][y] >= matrix[x][y+1]) && !visited[x][y+1] )\n             dfs(matrix,visited,x,y+1);\n        \n        //bottom is x+1,y\n             if(x+1<numRows && y>=0 && y<numColumns && (matrix[x][y] >= matrix[x+1][y]) && !visited[x+1][y])\n                 dfs(matrix,visited,x+1,y);\n        \n        //left is x,y-1\n            if(x>=0 && x<numRows && y-1>=0 && matrix[x][y] >= matrix[x][y-1] && !visited[x][y-1])\n                dfs(matrix,visited,x,y-1);\n        \n        \n    }\n}\n```
[]