Bug Report for https://neetcode.io/problems/trapping-rain-water - Need more test cases
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
Below test case or similar should be added, as existing test cases for submission are not restrictive enough.
height= [5, 1, 2, 0, 4]
I tried a very naive and unnecessarily complicated code as below (Python solution):
This solution shouldn't have been accepted as it fails on above test case, but it was accepted due to lack of variety of test cases.
class Solution:
def trap(self, height: List[int]) -> int:
left = 0
right = 1
max_area = 0
while(left < len(height)-1):
if (height[left] == 0):
left+=1
right = left+1
continue
if height[left+1] >= height[left]:
left+=1
right = left+1
continue
else:
area=0
while(right < len(height) and (height[right]< height[left])):
area += height[left] - height[right]
right+=1
if(right >= len(height)):
area = 0
right = len(height) - 1
initial_right = len(height)-1
while(left< right):
initial_right = right
while (height[right-1] < height[right] and left< right):
area+= height[initial_right] - height [right-1]
right -=1
#print(area)
right-=1
right = len(height)-1
max_area += area
#print(left, right, height[left], area)
left= right
right = left+1
return max_area
Below is the response from NeetBot for further understanding:
This edge case reveals a fundamental flaw: the backward scan only captures water in "valleys" that are monotonically increasing as you go rightwards from the left end, ignoring other dips.
Bug Report for https://neetcode.io/problems/trapping-rain-water - Need more test cases
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
Below test case or similar should be added, as existing test cases for submission are not restrictive enough.
height= [5, 1, 2, 0, 4]
I tried a very naive and unnecessarily complicated code as below (Python solution):
This solution shouldn't have been accepted as it fails on above test case, but it was accepted due to lack of variety of test cases.
Below is the response from NeetBot for further understanding: