Min Heap| Trapping Rainwater I alike approach
Intuition\n Describe your first thoughts on how to solve this problem. \nThe blocking boundary for each block is now a set of blocks(which is like a perimeter),
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe blocking boundary for each block is now a set of blocks(which is like a perimeter), which is not the maximum of all blocks in the same row and column.\nThere could still be a water spill if we block all the four paths.\n\nTo evaluate the volume in Trapping Rainwater 1 we were making use of the minimum of the maximum of the heights from the two paths- left and right . Here there can be many paths. We will start moving from the path which has the minimum blocking height among all.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. To implement this we need a min heap. Initially all the boundary blocks i.e the outer edge elements of the matrix will be pushed.\n2. Then whatever is the minimum boundary height we will shift to the adjacent of that point and update our answer. If this block can not store water then the boundary value will be updated to the value of the blocks height else we continue with the previous boundary.  Now push this new point to the priority queue . \n3. The answer for the adjacent blocks of top element in the min heap is only depending on what is the current minimum of the maximum from all paths.  \n# Complexity\n- Time complexity: O(m*n(log(m*n)))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(m*n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n \n# Code\n```\nclass Solution {\npublic:\n    int trapRainWater(vector<vector<int>>& heightMap) {\n        int n=heightMap.size();\n        int m=heightMap[0].size();\n        priority_queue<pair<int,pair<int,int>>> pq;\n        \n        int vis[n+1][m+1];\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(i==0 || j==0 || j==m-1 ||i==n-1){\n                    pq.push({-heightMap[i][j],{i,j}});\n                    vis[i][j]=1;\n                }\n                else{\n                    vis[i][j]=-1;\n                }\n            }\n        }\n        vector<vector<int>> dir={{1,0},{-1,0},{0,1},{0,-1}};\n        int ans=0;\n        while(!pq.empty()){\n            int x=pq.top().second.first;\n            int y=pq.top().second.second;\n            int minofmax=-1*pq.top().first;\n            pq.pop();\n            for(int i=0;i<4;i++){\n                int newx= x+dir[i][0];\n                int newy= y+dir[i][1];\n                \n                if(newx>=0 && newx<n && newy>=0 && newy<m &&vis[newx][newy]!=1){\n                    vis[newx][newy]=1;\n                    if(minofmax>=heightMap[newx][newy]){\n                        ans+=minofmax-heightMap[newx][newy];\n                    }\n                    pq.push({min(-minofmax,-heightMap[newx][newy]),{newx,newy}});\n                }\n               \n            }\n        }\n        return ans;\n    }\n};\n```
['Heap (Priority Queue)', 'C++']