Company: MediaNet_23july
Difficulty: medium
Rainwater Harvesting Problem Description You are given an N x M matrix A of positive integers. It describes a 2-D elevation map: the cell in row i and column j is a unit square of ground whose height is A[i][j] . Rain falls on the whole map until no more water can stay on it. Return the total volume of water that remains trapped after raining. The water behaves as follows: Water moves between cells that share a side (up, down, left, right). It never moves diagonally. Water that reaches a cell in the first row, the last row, the first column or the last column runs off the map, so those outer cells never hold water. Water settles only when it cannot flow anywhere lower: a cell holds water up to level L only if every route from that cell to the outer edge of the map passes through some cell whose height is at least L . A cell of height h whose settled water surface is at level L holds L - h units of water. (inferred - the source says only "a 2D elevation map" and "the volume of water it