Amount of Water
Submissions: 6117   Accuracy:

33.65%

  Difficulty: Easy   Marks: 2

An array A containing heights of building was given. Its a rainy season. Calculate the amount of water collected between all the buildings.

 

Histograms with no space in between
Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N, N is the number of buildings. The second line of each test case contains N input H[i],height of buildings.

Output:
Print the amount of water collected between all the buildings.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 103
1 ≤ H[i] ≤ 103

Example:
Input:
1
6
1 5 3 7 4 2

Output:
2

Explanation:
Testcase 1: Water are trapped by block at index 2 (0-based indexing) only and can trap 2 units of water.

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.