C++ || Priority Queue || BFS
\n\n    #define ppi pair>\n    Solution {\n    public:\n\t  \n      int DR[4]={1,0,-1,0};\n      int DC[4]={0,1,0,-1};\n    \n    int trapRainWater(vector>& hei
\n\n    #define ppi pair<int,pair<int,int>>\n    Solution {\n    public:\n\t  \n      int DR[4]={1,0,-1,0};\n      int DC[4]={0,1,0,-1};\n    \n    int trapRainWater(vector<vector<int>>& heightMap) {\n         int n=heightMap.size();\n         int m=heightMap[0].size();\n    \n        priority_queue<ppi,vector<ppi>,greater<ppi>> pq;\n        vector<vector<bool>>vis(n,vector<bool>(m,false));\n        \n        for(int i=0;i<n;i++){           \n            for(int j=0;j<m;j++){\n                if(i==0 || j==0 || i==n-1 || j==m-1){\n\t\t\t\t    pq.push({heightMap[i][j] , {i,j}}) ;\n\t\t\t\t\tvis[i][j]=true;\n\t\t\t\t}\n            }\n        }\n           \n        int total=0;\n        int minBdht=0;        \n        while(!pq.empty())       \n        {\n            int currHeight = pq.top().first;\n            int x=pq.top().second.first;\n            int y=pq.top().second.second;\n            pq.pop();\n            \n            minBdht = max( currHeight , minBdht);\n            \n          \n            \n            for(int i=0;i<4;i++)\n            {\n                int newX = x+DR[i];\n                int newY = y+DC[i];\n                \n                if(newX>=0 && newX<n && newY>=0 && newY<m && !vis[newX][newY] )  // edgecase of bfs\n                {\n                       pq.push({heightMap[newX][newY] , {newX , newY}});\n                       vis[newX][newY]=true;\n                       if(heightMap[newX][newY] < minBdht)\n                       {\n                           total += (minBdht-heightMap[newX][newY]); \n                       }              \n                }\n                \n            }\n            \n        }\n        return total;\n    }\n    };
['Breadth-First Search', 'C']