So, this is a leetcode hard problem on trapping rainwater.
Summary:
1. Calculate individual water trapped at every index and sum all of it.
2. To calculate individual water trapped:
individual water trapped = min(leftheight,rightheight)-barheight
if(individual water trapped) is less than zero then consider zero.
3. Sum all of it.