How many water can a tile contains depend on max(itself, shortest neighbor).
Start from the outermost tile. Put them one by one in a Min-heap priority queue, and mark them true in visited.
Each time pop the shortest pillar from PQ, and check all its neighbors.
If it’s higher than some of its neighbors
Fill the neighbor up.
Put them in the PQ.
Mark as visited
res = curHeight - neighbor's height.
Terminate when the queue is empty.
Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.
1 2 3 4 5
Input: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] Output: 4 Explanation: After the rain, water is trapped between the blocks. We have two small pounds 1 and 3 units trapped. The total volume of water trapped is 4.