✅Accepted || ✅Short & Simple || ✅Best Method || ✅Easy-To-Understand
\n# Code\n\nclass Solution {\npublic:\n    void bfs(vector<vector<int>>& heights, queue<pair<int, int>>& q, vector<vector<bool>>& v)\n    {\n        int x[5]={0
\n# Code\n```\nclass Solution {\npublic:\n    void bfs(vector<vector<int>>& heights, queue<pair<int, int>>& q, vector<vector<bool>>& v)\n    {\n        int x[5]={0, 1, 0, -1, 0};\n        int m=heights.size();\n        int n=heights[0].size();\n        while(!q.empty())\n        {\n            // cout<<"d";\n            auto p=q.front();\n            q.pop();\n            int i=p.first;\n            int j=p.second;\n            for(int k=0;k<4;k++)\n            {\n                int r=i+x[k];\n                int c=j+x[k+1];\n                if(r>=0 && r<m && c>=0 && c<n && heights[r][c]>=heights[i][j] && v[r][c]==false)\n                {\n                    v[r][c]=true;\n                    q.push({r, c});\n                }\n            }\n        }\n        // for(int i=0;i<m;i++)\n        // {\n        //     for(int j=0;j<n;j++)\n        //     cout<<v[i][j]<<" ";\n        //     cout<<"\\n";\n        // }\n    }\n    vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n        int m=heights.size();\n        int n=heights[0].size();\n        vector<vector<bool>> p(m, vector<bool>(n, false));\n        vector<vector<bool>> a(m, vector<bool>(n, false));\n        queue<pair<int, int>> q1, q2;\n        for(int j=0;j<n;j++)\n        {\n            q1.push({0, j});\n            p[0][j]=true;\n            q2.push({m-1, j});\n            a[m-1][j]=true;\n        }\n        for(int i=0;i<m;i++)\n        {\n            q1.push({i, 0});\n            p[i][0]=true;\n            q2.push({i, n-1});\n            a[i][n-1]=true;\n        }\n        bfs(heights, q1, p);\n        cout<<"\\n";\n        bfs(heights, q2, a);\n        vector<vector<int>> ans;\n        for(int i=0;i<m;i++)\n        {\n            for(int j=0;j<n;j++)\n            if(p[i][j] && a[i][j])\n            ans.push_back({i, j});\n        }\n        return ans;\n    }\n};\n```\nPlease **UPVOTE** if it helps \u2764\uFE0F\uD83D\uDE0A\nThank You and Happy To Help You!!
['C++']