Diagram and code  Explanation 👍..
Example \n \n\n\n# blue color represent   pacific water that in matrix \n\n\n\n\n# Green color represent atlantic water\n\n\n\n# Orange color represent common p
# Example \n \n![Screenshot 2023-11-27 021723.png](https://assets.leetcode.com/users/images/d2f289a9-f50b-49d0-8c36-df6d32bcb60d_1701031822.1818397.png)\n\n# blue color represent   pacific water that in matrix \n\n![Screenshot 2023-11-27 021755.png](https://assets.leetcode.com/users/images/98bd7d4e-454b-4538-9aa5-67f0c58766d7_1701031867.2451808.png)\n\n\n# Green color represent atlantic water\n![Screenshot 2023-11-27 021836.png](https://assets.leetcode.com/users/images/da21bcbb-c9c3-4453-ba7d-4703f932088e_1701031945.5698025.png)\n\n\n# Orange color represent common part that connect pacific and atlantic water .. which is our answer \n![Screenshot 2023-11-27 021920.png](https://assets.leetcode.com/users/images/5d9d409c-7641-4a94-8412-a11efdfb6210_1701031979.1196177.png)\n\n### Initialization:\n\nTwo boolean matrices, \'pacific\' and \'Atlantic,\' are created to mark cells that are reachable from the Pacific and Atlantic oceans, respectively.\n\nTwo queues, \'qpacific\' and \'qAtlantic,\' are created to perform Breadth-First Search (BFS) traversal from the ocean edges.\n\n### BFS for Pacific:\n\nStarting from the top and left edges of the matrix, BFS is performed to mark cells that are reachable from the Pacific Ocean. The BFS function is called with the \'qpacific\' queue.\nDuring BFS, if a cell is reachable from the Pacific Ocean, it is marked in the \'pacific\' matrix.\n\n\n### BFS for Atlantic:\n\nStarting from the bottom and right edges of the matrix, BFS is performed to mark cells that are reachable from the Atlantic Ocean. The BFS function is called with the \'qAtlantic\' queue.\nDuring BFS, if a cell is reachable from the Atlantic Ocean, it is marked in the \'Atlantic\' matrix.\n\n### Check Common Cells:\n\nAfter both BFS operations, the code iterates through all cells in the matrix and checks if a cell is marked as reachable from both the Pacific and Atlantic oceans.\nIf a cell satisfies this condition, its coordinates are added to the \'ans\' list.\n\n### Return Result:\n\nThe final result is a list of cell coordinates (\'ans\') representing the cells that are reachable from both the Pacific and Atlantic oceans.\n\n# Complexity\n- Time complexity: O(n * m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n * m)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    static class Pair {\n        int row;\n        int col;\n\n        Pair(int row, int col) {\n            this.row = row;\n            this.col = col;\n        }\n    }\n\n    public List<List<Integer>> pacificAtlantic(int[][] heights) {\n        List<List<Integer>> ans = new ArrayList<>();\n        int n = heights.length; // row\n        int m = heights[0].length; // col\n\n        boolean pacific[][] = new boolean[n][m];\n        boolean Atlantic[][] = new boolean[n][m];\n\n        Queue<Pair> qpacific = new LinkedList<>();\n        Queue<Pair> qAtlantic = new LinkedList<>();\n\n        for (int i = 0; i < m; i++) {\n            qpacific.add(new Pair(0, i));\n            pacific[0][i] = true;\n            qAtlantic.add(new Pair(n - 1, i));\n            Atlantic[n - 1][i] = true;\n        }\n\n        for (int i = 0; i < n; i++) {\n            qpacific.add(new Pair(i, 0));\n            pacific[i][0] = true;\n            qAtlantic.add(new Pair(i, m - 1)); \n            Atlantic[i][m - 1] = true;\n        }\n\n        bfs(heights, pacific, qpacific);\n        bfs(heights, Atlantic, qAtlantic);\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                if (pacific[i][j] && Atlantic[i][j]) {\n                    ans.add(Arrays.asList(i, j));\n                }\n            }\n        }\n        return ans;\n    }\n\n    static void bfs(int height[][], boolean[][] vis, Queue<Pair>q) {\n        int n = height.length;\n        int m = height[0].length;\n\n        int[] delrow = {-1, 0, 0, 1};\n        int[] delcol = {0, -1, 1, 0};\n\n        while (!q.isEmpty()) {\n            int row = q.peek().row;\n            int col = q.peek().col;\n\n           q.poll();\n\n            for (int i = 0; i < 4; i++) {\n                int nrow = row + delrow[i];\n                int ncol = col + delcol[i];\n\n                if (nrow >= 0 && ncol >= 0 && nrow < n && ncol < m && !vis[nrow][ncol]\n                        && height[nrow][ncol] >= height[row][col]) {\n                    q.add(new Pair(nrow, ncol));\n                    vis[nrow][ncol] = true;\n                }\n            }\n        }\n    }\n}\n\n```
['Breadth-First Search', 'Graph', 'Java']