category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

Tags: prefix-sum

42. Trapping Rain Water

implementation ```cpp #define vi vector class Solution { public: int trap(vector& height) { int n = height.size(); vi mx_left(n); vi mx_right(n); mx_left[0] = height[0]; mx_right[n - 1] = height[n - 1]; for (int i = 1; i < n; i++) { mx_left[i] = max(height[i], mx_left[i - 1]); } for (int i = n - 2; i >= 0; i--) { mx_right[i] = max(height[i], mx_right[i + 1]); } int ans = 0; for (int i = 0; i < n; i++) { ans += min(mx_left[i], mx_right[i]) - height[i]; } return ans; } }; ``` </details>