Simple BFS SOLUTION ! Don't get confused with trapping rainwater 1 problem.
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    class Pair implements Comparable<Pair>{\n        int row;\n        int col;\n        int height;\n        public Pair(int x, int y, int h){\n            this.row=x;\n            this.col=y;\n            this.height=h;\n        }\n        public int compareTo(Pair a){\n            return this.height - a.height;\n        }\n    }\n\n    public int trapRainWater(int[][] heightMap) {\n        int n = heightMap.length;\n        int m = heightMap[0].length;\n\n        boolean[][] vis = new boolean[n][m];\n        PriorityQueue<Pair> pq = new PriorityQueue<>();\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                    pq.add(new Pair(i,j,heightMap[i][j]));\n                    vis[i][j]=true;\n                }\n            }\n        }\n        int[][] dirs = {{0,1},{0,-1},{-1,0},{1,0}};\n        int traps = 0;\n\n        while(!pq.isEmpty()){\n            Pair rem = pq.poll();\n            for(int[] dir : dirs){\n                int rowx = rem.row + dir[0];\n                int colx = rem.col + dir[1];\n\n                if(rowx>0 && rowx<n && colx>0 && colx<m && vis[rowx][colx]==false){\n                    vis[rowx][colx]=true;\n                    int nextHeight = heightMap[rowx][colx];\n                    if(nextHeight<rem.height){\n                        traps+=rem.height-nextHeight;\n                        heightMap[rowx][colx]=rem.height;\n                    } \n                    pq.offer(new Pair(rowx,colx,heightMap[rowx][colx]));\n                }\n            }\n        }\n        return traps;\n        \n    }\n}\n```
['Array', 'Breadth-First Search', 'Java']