✅C++||priority queue||easy to understand
```\nclass Solution {\npublic:\n    int dir[5]={1,0,-1,0,1};\n    int trapRainWater(vector>& heightMap)\n    {\n        typedef pair cell;\n        priority_que
```\nclass Solution {\npublic:\n    int dir[5]={1,0,-1,0,1};\n    int trapRainWater(vector<vector<int>>& heightMap)\n    {\n        typedef pair<int,int> cell;\n        priority_queue<cell,vector<cell>,greater<cell>> pq;\n        int row=heightMap.size(),col=heightMap[0].size();\n        vector<vector<int>> vis(row,vector(col,0));\n        int ans=0,mx=INT_MIN;\n        for(int i=0;i<row;i++)\n        {\n            for(int j=0;j<col;j++)\n            {\n                if(!(i==0||j==0||i==row-1||j==col-1))\n                    continue;\n                pq.push({heightMap[i][j],i*col+j});\n                vis[i][j]=1;\n            }\n        }\n        while(!pq.empty())\n        {\n            cell p=pq.top();\n            pq.pop();\n            int height=p.first;\n            int x=p.second/col,y=p.second%col;\n            mx=max(mx,height);\n            for(int i=0;i<4;i++)\n            {\n                int nx=x+dir[i],ny=y+dir[i+1];\n                if(nx<0||ny<0||nx>=row||ny>=col||vis[nx][ny])\n                    continue;\n                vis[nx][ny]=1;\n                if(heightMap[nx][ny]<mx)\n                    ans+=mx-heightMap[nx][ny];\n                pq.push({heightMap[nx][ny],nx*col+ny});\n            }\n            \n        }\n        return ans;\n        \n    }\n};\n//if you like the solution plz upvote.
['C', 'Heap (Priority Queue)']