Given an array arr[] of N non-negative integers representing the height of blocks. If width of each block is 1, compute how much water can be trapped between the blocks during the rainy season.
// Function to find the trapped water between the blocks. public: longlongtrappingWater(int arr[], int n){ vector<pair<int, int>> st; longlong res = 0, l = 0, r = n - 1, mi = 0; while(l < r) { if(arr[l] < arr[r]) { if(arr[l] <= mi) res -= arr[l++]; else { res -= mi; res += (r - l - 1) * (arr[l] - mi); mi = arr[l++]; } } else { if(arr[r] <= mi) res -= arr[r--]; else { res -= mi; res += (r - l - 1) * (arr[r] - mi); mi = arr[r--]; } } } return res; } };