-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Bug Report for https://neetcode.io/problems/sliding-window-maximum
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
The test cases do not adequately cover all cases it seems, this incorrect solution was able to pass all of the current ones:
class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
l, r = 0, 0
max_num, sec_max = -10000, -10000
while ((r-l) < (k-1)):
if (nums[r] > max_num):
max_num = nums[r]
sec_max = -10000
elif (nums[r] > sec_max):
sec_max = nums[r]
r += 1
res = []
while (r < len(nums)):
if (nums[r] > max_num):
max_num = nums[r]
sec_max = -10000
elif (nums[r] > sec_max):
sec_max = nums[r]
res.append(max_num)
if (nums[l] == max_num):
max_num = sec_max
sec_max = -10000
l += 1
r += 1
return res
A test case with a descending array should address this, such as:
[5, 4, 3, 2, 1] k= 3
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels