PROBLEM : AT002
DIFFICULTY : Medium
PREREQUISITES : Math
You are given with a situation to find the amount of water that is filled between adjacent buildings. You are provided with the data of their heights.Also you must consider that there is no gap between adjacent buildings and width of each building is one. In order to find the amount you must consider three adjacent buildings and should find the gap between them by considering the minimum height of the end side buildings from which the height of the middle building is subtracted,by considering all possibilities.
The program is divided into different functions to make the logic more understandable.
int arr - This integer array STORES the heights of all the adjacent buildings where the number of elements in the array is the number of buildings.
int findWater(int arr,int start,int end): This function takes the array which stores the heights of the buildings and two integer values which points start and end building in the buildings array and returns the total amount of the water that can be stored due to rain.
int max(int a,int b):Upon taking two integer values this function return the value of the integer which is larger.
int min(int a,int b):Upon taking two integer values this function return the value of the integer which is smaller.
Solution: click here to see the solution