Hacktoberfest2023-Open-source-
Hacktoberfest2023-Open-source- copied to clipboard
Trapping Rain Water in Python
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!"
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))
hey could you assign this issue to me will be happy to contribute
assign me
Hi Robinrai2612 could you assign this issue to me
I wish to contribute. Kindly assign me this issue.