C++ || Shortest Solution || DFS || Very easy to understand
\nclass Solution {\npublic:\n\n    \n   void dfs(int i,int j,vector<vector<int>>& height, vector<vector<bool>> &ocean)\n   {\n        \n        int n=height.siz
```\nclass Solution {\npublic:\n\n    \n   void dfs(int i,int j,vector<vector<int>>& height, vector<vector<bool>> &ocean)\n   {\n        \n        int n=height.size();\n        int m=height[0].size();\n        if(ocean[i][j]==false)\n          ocean[i][j]=true;\n          if(i>0 && height[i-1][j]>=height[i][j] && ocean[i-1][j]==false)dfs(i-1,j,height,ocean);\n          if(j>0 && height[i][j-1]>=height[i][j] && ocean[i][j-1]==false)dfs(i,j-1,height,ocean);\n          if(i<n-1 && height[i+1][j]>=height[i][j] && ocean[i+1][j]==false)dfs(i+1,j,height,ocean);\n          if(j<m-1 && height[i][j+1]>=height[i][j] && ocean[i][j+1]==false)dfs(i,j+1,height,ocean);\n          return;\n   }\n    \n    vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n         vector<vector<int>> ans;\n        \n           \n        int n=heights.size();\n        int m=heights[0].size();\n         vector<vector<bool>> pacific(n+1,vector<bool>(m+1,false));\n         vector<vector<bool>> atlantic(n+1,vector<bool>(m+1,false));\n  \n      \n        //Check Edges for Pacific ocean\n        \n        for(int i=0;i<n;i++)\n        {\n          for(int j=0;j<m;j++)\n          {\n              if(i==0 || j==0)\n                dfs(i,j,heights,pacific);  \n          }\n        }\n        \n        \n        //Check Edges for Atlantic ocean\n        for(int i=0;i<n;i++)\n        {\n          for(int j=0;j<m;j++)\n          {\n              if(i==n-1 || j==m-1)\n                dfs(i,j,heights,atlantic);  \n          }\n        }\n       \n        \n        //If water can flow from a cell in both atlantic and pacific add that to our answer.\n           for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                if(atlantic[i][j]==true && pacific[i][j]==true)\n                     ans.push_back({i,j});\n            }\n        }\n        return ans;\n        \n    }\n};\n\n```\nPlease upvote if it was helpful.\n
['Depth-First Search', 'C', 'C++']