Trapping Rain Water

You have been given a long type array/list 'ARR' of size 'N'. It represents an elevation map wherein 'ARR[i]' denotes the elevation of the 'ith' bar. Print the total amount of rainwater that can be trapped in these elevations.

Note :
The width of each bar is the same and is equal to 1.
Input format :
The first line contains an integer 'T' which denotes the number of test cases. Then the test cases follow.

The first line of each test case contains an integer 'N' representing the size of the array/list.

The second line contains 'N' single space-separated integers representing the elevation of the bars.
Output Format :
For each test case, print in a single line a single integer denoting the total water that can be trapped.

The output of each test case will be printed in a separate line.
Note :
You don't need to print anything. It has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10
0 <= N <= 10^4
0 <= ARR[i] <= 10^9

Time Limit : 1 sec
Be the first one to answer
Add answer anonymously...
Mphasis Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter