Hacktoberfest2023-Open-source- icon indicating copy to clipboard operation
Hacktoberfest2023-Open-source- copied to clipboard

Trapping Rain Water in Python

Open Robinrai2612 opened this issue 1 year ago • 5 comments

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.

"Hello @DHEERAJHARODE , could you kindly assign this issue to me for Hacktoberfest-2023? Thank you!"

Robinrai2612 avatar Oct 06 '23 09:10 Robinrai2612

def rain(arr): ans = 0 temp = 0 prev = 0 for i in range(len(arr)): if arr[i] > prev and temp == 0: prev = arr[i] elif arr[i] >= prev: ans += temp prev = arr[i] temp = 0 else: if i != len(arr)-1 and arr[i] < max(arr[i+1:]): temp += prev - arr[i] else: ans += arr[i] temp = 0 prev = arr[i] return ans

arr = [2, 0, 3, 0, 2, 0, 4] print(rain(arr))

sudip1234567 avatar Oct 06 '23 13:10 sudip1234567

hey could you assign this issue to me will be happy to contribute

aspiringgarv avatar Oct 09 '23 08:10 aspiringgarv

assign me

ABHINAV0307 avatar Oct 12 '23 04:10 ABHINAV0307

Hi Robinrai2612 could you assign this issue to me

mallikarjuna4406 avatar Oct 25 '23 12:10 mallikarjuna4406

I wish to contribute. Kindly assign me this issue.

Ashima2003 avatar Oct 29 '23 03:10 Ashima2003