Trapping Rain Water II
Problem statement
You are given an m x n integer matrix heightMap, where each value is the height of one unit-width cell in a two-dimensional terrain.
After rain falls, water can remain above a cell only when surrounding terrain prevents it from flowing to the outer boundary.
Return the total volume of trapped water.
Function
trapRainWater(heightMap: int[][]) → intExamples
Example 1
heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]return = 4The boundary-driven water level traps four units across the two interior low regions.
Example 2
heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]return = 10The boundary height is three. The eight height-two cells hold one unit each, and the center holds two.
Example 3
heightMap = [[1,1,1],[1,0,1],[1,1,1]]return = 1The center cell is enclosed by height-one boundary cells.
Constraints
1 <= m, n <= 200.m * n <= 40000.0 <= heightMap[i][j] <= 20000.