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
The question asks to find the total amount of rainwater that can be trapped in the given elevation map.
Iterate through the array and find the maximum height on the left and right side of each bar.
Calc...read more
The idea is to traverse every array element and find the highest bars on the left and right sides. Take the smaller of two heights. The difference between the smaller height and height of the current ...read more
The idea here is to travel over every elevation on the map and calculate the units of water the elevation can store.
Here is the algorithm :
- Iterate over every elevation or element...read more
The idea here is to pre-compute the maximum elevation on the left and right for every element in a most optimized way.
Here is the algorithm :
- Create two lists or arrays, ...read more
The idea here is to find the maximum elevation in the array by iterating over the array once. Say, the max elevation or height is ‘PEAK’.
Taking the ‘PEAK’ as a reference point,...read more
Top Unthinkable Solutions Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Unthinkable Solutions Software Developer
Reviews
Interviews
Salaries
Users/Month