Mozilla-Campus-Club-Cummins / HacktoberFest23_MozillaCCEW

0 stars 0 forks source link

#Issue 66 : Added Code for Trapping Rain Water in C++ #143

Closed srushtikage closed 1 year ago

srushtikage commented 1 year ago

66

For this problem I have taken 2 arrays of size n(same as that of input array). Then I have stored the maximum value of element while tracing the array from left to right in l[n] & from right to left in r[n]. Then I added the min(l[i], r[i]) - a[i] to the rainWater variable. Time complexity : O(n) Space Complexity : O(n)