Trapping Rain Water II
https://leetcode.com/problems/trapping-rain-water-ii/
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining.
Example:
Given the following 3x6 height map:
[
[1,4,3,1,3,2],
[3,2,1,3,2,4],
[2,3,3,2,3,1]
]
Return 4.

The above image represents the elevation map [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] before the rain.
After the rain, water is trapped between the blocks. The total volume of water trapped is 4.

testcase:(where my code fails)
[12,13,1,12],
[13,4,13,12],
[13,8,10,12],
[12,13,12,12],
[13,13,13,13]
4->min(13,13,13,13)=13-4=9
13->min(0)=9-0=9
8->min(13,13,13,12)=12-8=4
10->min(13,13,13,12)=12-10=2
13->min(0)=15-0;
12->min(0)=15-0;
my output: 15
expected output: 14
code:
```
class Solution {
boolean top=false;
boolean bottom=false;
boolean left=false;
boolean right=false;
public int trapRainWater(int[][] heightMap) {
int totalVolume=0;
for(int row=1;row<heightMap.length-1;row++){
for(int col=1;col<heightMap[0].length-1;col++){
//min(min(max height in top,max height in bottom),min(max height in right,max height in left));
int tempMaxAround=Math.min(Math.min(topMax(row-1,col,heightMap,heightMap[row][col]),bottomMax(row+1,col,heightMap,heightMap[row][col])),Math.min(leftMax(row,col-1,heightMap,heightMap[row][col]),rightMax(row,col+1,heightMap,heightMap[row][col])));
if(top&&left&&bottom&&right){
totalVolume+=(tempMaxAround-heightMap[row][col]);
top=false;
bottom=false;
left=false;
right=false;
}
}
}
return totalVolume;
}
public int topMax(int row,int col,int mat[][],int temp){
int max=0;
while(row>=0){
if(temp<mat[row][col]){
top=true;
max=Math.max(max,mat[row][col]);
}
row--;
}
return max;
}
public int bottomMax(int row,int col,int mat[][],int temp){
int max=0;
while(row<mat.length){
if(temp<mat[row][col]){
bottom=true;
max=Math.max(max,mat[row][col]);
}
row++;
}
return max;
}
public int leftMax(int row,int col,int mat[][],int temp){
int max=0;
while(col>=0){
if(temp<mat[row][col]){
left=true;
max=Math.max(max,mat[row][col]);
}
col--;
}
return max;
}
public int rightMax(int row,int col,int mat[][],int temp){
int max=0;
while(col<mat[0].length){
if(temp<mat[row][col]){
right=true;
max=Math.max(max,mat[row][col]);
}
col++;
}
return max;
}
}
```