Amount of Water
Submissions: 4929   Accuracy:

37.85%

  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


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

to report an issue on this page.