Easy BFS Solution | C++| Time(N*M) | Space(N*M)
\nclass Solution {\npublic:\n    vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n        \n\t\tqueue<pair<int,int>>q;\n\tset<vector<int>>an
```\nclass Solution {\npublic:\n    vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n        \n\t\tqueue<pair<int,int>>q;\n\tset<vector<int>>ans;\n\tmap<pair<int,int>,bool>atlantic,pacific;\n\n\tfor(int count=0;count<heights[0].size();++count)\n\t\tatlantic[{0,count}]=true,q.push({0,count});\n\n\t\tfor(int count =0;count<heights.size();++count)\n\t\t\t\tatlantic[{count,0}]=true,q.push({count,0});\n\n\n\tint dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}};\n\n\twhile(!q.empty())\n\t{\n\t\tint x = q.front().first;\n\t\tint y =  q.front().second;\n\n\t\tfor(int count =0;count<4;++count)\n\t\t{\n\t\t\tint i = x+dir[count][0];\n\t\t\tint j = y+dir[count][1];\n\n\t\t\tif(i>=0 && j>=0 && i<heights.size() && j<heights[0].size() && !atlantic[{i,j}] && heights[i][j]>=heights[x][y])\n\t\t\t{\n\t\t\t\tatlantic[{i,j}]=1;\n\t\t\t\tq.push({i,j});\n\t\t\t}\n\t\t}\n\t\tq.pop();\n\t}\n\n\t for(int count=0;count<heights[0].size();++count)\n\t\tpacific[{heights.size()-1,count}]=true,q.push({heights.size()-1,count});\n\n\t for(int count=0;count<heights.size();++count)\n\t pacific[{count,heights[0].size()-1}]=true,q.push({count,heights[0].size()-1});\n\n\n\t  while(!q.empty())\n\t{\n\t\tint x = q.front().first;\n\t\tint y =  q.front().second;\n\t\tif(atlantic[{x,y}])\n\t\t\tans.insert({x,y});\n\t\tfor(int count =0;count<4;++count)\n\t\t{\n\t\t\tint i = x+dir[count][0];\n\t\t\tint j = y+dir[count][1];\n\n\t\t\tif(i>=0 && j>=0 && i<heights.size() && j<heights[0].size() && !pacific[{i,j}] && heights[i][j]>=heights[x][y])\n\t\t\t{\n\n\n\t\t\t\tpacific[{i,j}]=1;\n\t\t\t\tq.push({i,j});\n\t\t\t}\n\t\t}\n\t\tq.pop();\n\t}\n\n\treturn {ans.begin(),ans.end()};\n} \n\n};\n```
[]