Trapping Rain Water in 2-D Elevation Map
You're given an M * N matrix where each value represents the height of that cell on a 2-D elevation map. Your task is to determine the total volume of water that can be trapped after it rains.
Example:
Input:
matrix = [[5, 5, 5],
[5, 2, 3],
[6, 9, 8]]
Output:
1
Explanation:
The elevation map allows 1 unit volume of water to be trapped, as illustrated in the image.
Constraints:
1 <= T <= 10
1 <= M, N <= 100
1 <= matrix[i][j] <= 10^3
- Where ‘T’ is the number of test cases, ‘M’ and ‘N’ are the dimensions of the given matrix.
- Matrix[i][j] is the height of the cell at the ‘i-th’ row and ‘j-th’ column.
- Time Limit: 1 sec.
Note:
You don't need to print anything, as it has already been taken care of. Just implement the given function.
Be the first one to answer
Add answer anonymously...
Top ION Group Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in ION Group Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app