Python concise and readable solution 
Let the water flow from boundaries and increase flow height level by level and calculate trapped on fly.\n\nclass Solution:\n    def trapRainWater(self, heightM
Let the water flow from boundaries and increase flow height level by level and calculate trapped on fly.\n```\nclass Solution:\n    def trapRainWater(self, heightMap):\n        m, n, heap, trapped = len(heightMap), len(heightMap and heightMap[0]), [], 0\n        for i in range(m):\n            for j in range(n):\n                if i in {0, m - 1} or j in {0, n - 1}:\n                    heapq.heappush(heap, (heightMap[i][j], i, j))\n                    heightMap[i][j] = -1          \n        while heap:\n            h, i, j = heapq.heappop(heap)\n            for x, y in ((i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)):\n                if 0 < x < m - 1 and 0 < y < n - 1 and heightMap[x][y] != -1:\n                    trapped += max(h - heightMap[x][y], 0)\n                    heapq.heappush(heap, (max(heightMap[x][y], h), x, y))\n                    heightMap[x][y] = -1\n        return trapped\n```
[]