I faced the question is that I only know 1d array method, but how can I change the code to suit for 2D array.
Give you a 2D array which means the height of the mountains.
And count the total water volume in this array.
Note: If surrounding elements are higher then a element, then it will be a lake.
The water volume of this lake is equal to (the lowest height of surrounding elements – height of this element)
public class moonlake {
public int count_water_volumn(int[][] height);
}
class GFG{
public static int maxArea(int[] a)
{
int Area = 0;
for(int i = 0; i < a.length; i++)
{
for(int j = i + 1; j < a.length; j++)
{
Area = Math.max(
Area, Math.min(a[i], a[j]) *
(j - i));
}
}
return Area;
}