C++ solution with code using priority queue
idea is based on this approach - https://www.youtube.com/watch?v=cJayBq38VYw\n\nclass pointData{\n  public:\n    int row;\n    int col;\n    int value;\n    poi
idea is based on this approach - https://www.youtube.com/watch?v=cJayBq38VYw\n```\nclass pointData{\n  public:\n    int row;\n    int col;\n    int value;\n    pointData(int i,int j,int val){\n        row =  i;\n        col = j;\n        value = val;\n    }\n};\n\nbool operator < (pointData pd1,pointData pd2){\n    if(pd1.value < pd2.value){\n        return false;\n    }\n    return true;\n}\n\nclass Solution {\npublic:\n    int trapRainWater(vector<vector<int>>& heightMap) {\n        \n        int row = heightMap.size();\n        if(row == 0){\n            return 0;\n        }\n        int col = heightMap[0].size();\n        \n        priority_queue<pointData> pq;\n        set<pair<int,int>> st;\n        \n        for(int i=0;i<row;i++){\n            pointData pd(i,0,heightMap[i][0]);\n            pq.push(pd);\n            st.insert(make_pair(i,0));\n        }\n        \n        for(int i=0;i<row;i++){\n            pointData pd(i,col-1,heightMap[i][col-1]);\n            pq.push(pd);\n            st.insert(make_pair(i,col-1));\n        }\n        \n        for(int i=1;i<col-1;i++){\n            pointData pd(0,i,heightMap[0][i]);\n            pq.push(pd);\n            st.insert(make_pair(0,i));\n        }\n        \n        for(int i=1;i<col-1;i++){\n            pointData pd(row-1,i,heightMap[row-1][i]);\n            pq.push(pd);\n            st.insert(make_pair(row-1,i));\n        }\n        \n        \n        \n        \n        int ans = 0;\n        int max = INT_MIN;\n        \n        while(!pq.empty()){\n            \n            pointData pd = pq.top();\n            pq.pop();\n            int i = pd.row;\n            int j = pd.col;\n            if(pd.value > max){\n                max = pd.value;\n            }\n            \n            if(i-1 >=0){\n                int r = i-1;\n                int c = j;\n                pair<int,int> p = make_pair(r,c);\n                if(st.find(p) == st.end()){\n                    if(heightMap[r][c] <= max){\n                        ans += max - heightMap[r][c];\n                    }    \n                    st.insert(p);\n                    pointData pd1(r,c,heightMap[r][c]);\n                    pq.push(pd1);\n                }\n            }\n            \n            if(j-1 >=0){\n                int r = i;\n                int c = j-1;\n                pair<int,int> p = make_pair(r,c);\n                if(st.find(p) == st.end()){\n                    if(heightMap[r][c] <= max){\n                        ans += max - heightMap[r][c];\n                    }    \n                    st.insert(p);\n                    pointData pd1(r,c,heightMap[r][c]);\n                    pq.push(pd1);\n                }\n            }\n            \n            if(i+1  < row){\n                int r = i+1;\n                int c = j;\n                pair<int,int> p = make_pair(r,c);\n                if(st.find(p) == st.end()){\n                    if(heightMap[r][c] <= max){\n                        ans += max - heightMap[r][c];\n                    }    \n                    st.insert(p);\n                    pointData pd1(r,c,heightMap[r][c]);\n                    pq.push(pd1);\n                }\n            }\n            \n            if(j+1 < col){\n                int r = i;\n                int c = j+1;\n                pair<int,int> p = make_pair(r,c);\n                if(st.find(p) == st.end()){\n                    if(heightMap[r][c] <= max){\n                        ans += max - heightMap[r][c];\n                    }    \n                    st.insert(p);\n                    pointData pd1(r,c,heightMap[r][c]);\n                    pq.push(pd1);\n                }\n            }\n            \n            \n            \n            \n        }\n        \n        return ans;\n    }\n};\n```\n\nhope it helps\n
['C', 'Heap (Priority Queue)']