Company: Flipkart_8nov
Difficulty: medium
Rainwater Harvesting in Recharge Pit Description After a lecture on rainwater harvesting, the Director asks the students to build a recharge pit in the backyard. The pit is a grid of N x M cells -- one row per department and one cell per student. Each student raises or lowers the soil in their own cell, and the finished layout is recorded as integers: 0 is ground level, a negative value is a cell dug that deep, and a positive value is a cell raised that high. Every cell has unit area, so one unit of depth holds one unit of water. Rain then falls on the whole pit and any water that cannot flow off the edge of the grid stays in it. Water moves between cells that share a side, never diagonally, and it runs off freely once it reaches a cell on the outer border. Given the elevation map, report how much water the pit traps. Complete the function trapRainWater in the editor below. Input The first line holds two integers N and M separated by a space. Each of the next N lines holds M integers: