- Notifications
You must be signed in to change notification settings - Fork2.4k
Closed
Description
InNeetCode's video solution he only uses one deque to keep track of the indexes but inthe python solution here two deques are used, one keeping track of the index and the other keeping track of the value. Additionally you unnecessarily changed a while statement to an if statement. I made some changes to make the solution closer to the solution presented in the video as well as more efficient and readable
classSolution:defmaxSlidingWindow(self,nums:List[int],k:int)->List[int]:index_q=deque()res= []fori,ninenumerate(nums):whileindex_qandn>nums[index_q[-1]]:index_q.pop()index_q.append(i)ifindex_q[0]==i-k:index_q.popleft()ifi+1>=k:res.append(nums[index_q[0]])returnres
Metadata
Metadata
Assignees
Labels
No labels