Can i get the hint how to slove this problem?

any hint to solve this problem i cant think of any approach

hi @anubhavb11, i will provide you an insight ,
An element of the array can store water if there are higher bars on left and right. The amount of water to be stored in every element can be found out 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.

So the idea is for every array element and find the highest bars on left and right sides. Take the smaller of two heights. The difference between the smaller height and height of the current element is the amount of water that can be stored in this array element.

Now the complexity of your answer depends in the question how you will find the highest bars on the left and right ?

I have provided you more than just a hint , so take your time and think for the solution

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.