Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trapping Rain Water in Python #2129

Open
Robinrai2612 opened this issue Oct 6, 2023 · 5 comments
Open

Trapping Rain Water in Python #2129

Robinrai2612 opened this issue Oct 6, 2023 · 5 comments

Comments

@Robinrai2612
Copy link

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!"

@sudip1234567
Copy link

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))

@aspiringgarv
Copy link

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

@ABHINAV0307
Copy link

assign me

@mallikarjuna4406
Copy link

Hi Robinrai2612 could you assign this issue to me

@Ashima2003
Copy link

I wish to contribute. Kindly assign me this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants