C++ code using Priority Queue and Visited Matrix
learnt from pepcoding: visit their youtube channel for better understanding\n\nclass Solution {\npublic:\n    typedef pair<int, pair<int, int>> block;\nint trap
**learnt from pepcoding: visit their youtube channel for better understanding**\n```\nclass Solution {\npublic:\n    typedef pair<int, pair<int, int>> block;\nint trapRainWater(vector<vector<int>> &height)\n{\n\n    /*\n    we know that overflow must happen by crossing the boundary values, so we will store all the boundary values\n    we will process the element with minimum height, if water can\'t flow from minimum, it isn\'t possible through other elements\n\n    we will also mark a visited array, we won\'t process the values which are in the visited array\n\n    now we will use that minimum value with us, we will check for the neighbour of the value, if neighbours are on the boundary,\n    then we don\'t process them. now we have three condition here\n\n    1. neighbour[i][j]<min[i][j]-> in this condition we can store the value, we can add the value of\n    min[i][j]-neighbour[i][j] to our answer, we also know that now, we need to process the other values on that side too,\n    so, we will change the value of neighbour to that min[i][j] value\n\n    2.. neighbour=min[i][j]-> then we can\'t anything to our answer because water will flow over us here, so we here too move our\n    value to the neighbour and do same for neighbour\'s neighbour.\n\n    3. neighbour>min[i][j]-> then water is blocked by the neighbour itself, we will delegate to the neighbour to check blockage by it\n    */\n\n    priority_queue<block, vector<block>, greater<block>> mn;\n    int m = height.size();\n    int n = height[0].size();\n    bool vis[m][n];\n    memset(vis, false, sizeof(vis));\n    for (int i = 0; i < m; i++)\n    {\n        for (int j = 0; j < n; j++)\n        {\n            if (i == 0 || j == 0 || i == m - 1 || j == n - 1)\n            {\n                mn.push({height[i][j], {i, j}});\n                vis[i][j] = true;\n            }\n        }\n    }\n    vector<vector<int>> dir = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};\n    int water = 0;\n\n    while (mn.size() > 0)\n    {\n        block p = mn.top();\n        mn.pop();\n        for (int i = 0; i < dir.size(); i++)\n        {\n            int rowdash = p.second.first + dir[i][0];\n            int coldash = p.second.second + dir[i][1];\n\n            if (rowdash >= 0 && rowdash < m && coldash >= 0 && coldash < n && vis[rowdash][coldash] == false)\n            {\n                water += max(0, p.first - height[rowdash][coldash]);\n\n                if (p.first > height[rowdash][coldash])\n                    mn.push({p.first,{rowdash,coldash}});\n                else\n                    mn.push({height[rowdash][coldash],{rowdash, coldash}});\n                vis[rowdash][coldash] = true;\n            }\n            \n        }\n    }\n    return water;\n}\n};\n```
['Array', 'C', 'Heap (Priority Queue)']