Java Simple and easy to understand solution, using bfs, clean code with comments
PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\n\nclass Solution {\n    private static final int[][] DIRECTIONS = new int[][]{{0, 1}, {1, 0}, {-1, 0}, {0, -1}};\n 
**PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n\n```\nclass Solution {\n    private static final int[][] DIRECTIONS = new int[][]{{0, 1}, {1, 0}, {-1, 0}, {0, -1}};\n    \n    int rows;\n    int cols;\n    int[][] matrix;\n    \n    \n    public List<List<Integer>> pacificAtlantic(int[][] matrix) {\n        if(matrix.length == 0 || matrix[0].length == 0)\n            return new ArrayList<>();\n        \n        this.matrix = matrix;\n        rows = matrix.length;\n        cols = matrix[0].length;\n        \n        \n        \n        Queue<int[]> pacificQueue = new LinkedList();\n        Queue<int[]> atlanticQueue = new LinkedList();\n        \n        for(int i = 0; i < rows; i++){\n            pacificQueue.add(new int[]{i, 0});\n            atlanticQueue.add(new int[]{i, cols - 1});\n        }\n        \n        \n        for(int j = 0; j < cols; j++){\n            pacificQueue.add(new int[]{0, j});\n            atlanticQueue.add(new int[]{rows - 1, j});\n        }\n        \n        \n        int[][] pacificReachable = bfs(pacificQueue);\n        int[][] altanticReachable = bfs(atlanticQueue);\n        \n        \n        List<List<Integer>> commanCell = new ArrayList();\n        for(int i = 0; i < rows; i++){\n            for(int j = 0; j < cols; j++){\n                //marked\n                if(pacificReachable[i][j] == 1 && altanticReachable[i][j] == 1){\n                    commanCell.add(new ArrayList<Integer>(List.of(i, j)));\n                }\n            }\n        }\n        \n        \n        return commanCell;\n    }\n    \n    \n    private int[][] bfs(Queue<int[]> queue){\n        \n        int[][] reachable = new int[rows][cols];\n        \n        while(!queue.isEmpty()){\n            int[] cell = queue.remove();\n            \n            \n            //mark as reached this cell\n            reachable[cell[0]][cell[1]] = 1;\n            \n            for(int[] dir : DIRECTIONS){\n                int newRow = cell[0] + dir[0];\n                int newCol = cell[1] + dir[1];\n                \n                //Boundary check\n                if(newRow < 0 || newRow >= rows || newCol < 0 || newCol >= cols)\n                    continue;\n                \n                \n                //check already reached from pacific ocean or altantic ocean\n                if(reachable[newRow][newCol] > 0)\n                    continue;\n                \n                //check from.this cell we can reached to ocean or not\n                if(matrix[newRow][newCol] < matrix[cell[0]][cell[1]])\n                    continue;\n                \n                queue.offer(new int[]{newRow, newCol});\n            }\n        }\n        \n        return reachable;\n    }\n}\n```
['Backtracking', 'Breadth-First Search', 'Java']