RainWater Harvesting question

Answer not correct but compilation is successful

Rachit for this question, plz refer to online video given under array 1D problems, from there you will get a better idea on solution,