
Asked in ION Group
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.

AnswerBot
4mo
Calculate the total volume of water that can be trapped in a 2-D elevation map after rain.
Iterate over the matrix and find the maximum height on the borders.
Calculate the water trapped at each cell by...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at ION Group
Q. Explain the time complexity of a binary tree.
Q. What are the four pillars of OOP?
Q. Implement a stack using a linked list.
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for ION Group Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

