My logic matches with the example given still my code is not passing

My code logic seems perfect but when I execute it produces wrong answer as per given output which I think is given wrong. Please check if my code is perfect or not.
Here is my code:-

hi @sinchan1509_1a917d7b6cc3cbb9,
the logic is not correct

An element of an array can store water if there are higher bars on left and right. We can find the amount of water to be stored in every element by finding the heights of bars on the left and right sides. The idea is to compute the amount of water that can be stored in every element of the array.

A Simple Solution is to traverse every array element and find the highest bars on left and right sides. Take the smaller of two heights. The difference between smaller height and height of the current element is the amount of water that can be stored in this array element. The time complexity of this solution is O(n2).

An Efficient Solution is to the pre-compute highest bar on left and right of every bar in O(n) time. Then use these pre-computed values to find the amount of water in every array element.

try now if difficulties in implementation refer https://ideone.com/xeqV8B

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.