C++ || Clean and Simple || Beginner Friendly || Easy to Understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n        int m = heights.size();\n        int n = heights[0].size();\n\n        vector<vector<int>> visited_p(m, vector<int> (n, 0));\n        vector<vector<int>> visited_a(m, vector<int> (n, 0));\n        queue<pair<int, int>> q_pacific;\n        queue<pair<int, int>> q_atlantic;\n\n\n        for(int i=0;i<n;i++){\n            visited_p[0][i] = 1;\n            q_pacific.push({0, i});\n            visited_a[m-1][i] = 1;   \n            q_atlantic.push({m-1, i});\n        }\n\n        for(int i=0;i<m;i++){\n            visited_p[i][0] = 1;\n            q_pacific.push({i, 0});\n            visited_a[i][n-1] = 1;\n            q_atlantic.push({i, n-1});\n        }\n\n        vector<int> di = {+1, 0, 0, -1};\n        vector<int> dj = {0, +1, -1, 0};\n\n        while(!q_pacific.empty()){\n            int row = q_pacific.front().first;\n            int col = q_pacific.front().second;\n            q_pacific.pop();\n\n            for(int i=0;i<4;i++){\n                int n_row = row + di[i];\n                int n_col = col + dj[i];\n\n                if(n_row >= 0 && n_row < m && n_col >= 0 && n_col < n && visited_p[n_row][n_col] == 0){\n                    if(heights[n_row][n_col] >= heights[row][col]){\n                        visited_p[n_row][n_col] = 1;\n                        q_pacific.push({n_row, n_col});\n                    }\n                }\n            }\n        }\n\n        while(!q_atlantic.empty()){\n            int row = q_atlantic.front().first;\n            int col = q_atlantic.front().second;\n            q_atlantic.pop();\n\n            for(int i=0;i<4;i++){\n                int n_row = row + di[i];\n                int n_col = col + dj[i];\n\n                if(n_row >= 0 && n_row < m && n_col >= 0 && n_col < n && visited_a[n_row][n_col] == 0){\n                    if(heights[n_row][n_col] >= heights[row][col]){\n                        visited_a[n_row][n_col] = 1;\n                        q_atlantic.push({n_row, n_col});\n                    }\n                }\n            }\n        }\n\n        vector<vector<int>> ans;\n        for(int i=0;i<m;i++){\n            for(int j=0;j<n;j++){\n                if(visited_p[i][j] == 1 && visited_a[i][j] == 1)\n                    ans.push_back({i, j});\n            }\n        }\n        return ans;\n    }\n};\n```
['Breadth-First Search', 'C++']