Problem :

https://leetcode.com/problems/sliding-window-maximum/


My Solution :

from collections import deque

class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
dq = deque()
ret = []
for i in range(len(nums)):
if dq and dq[0] == i-k:
dq.popleft()
while dq and nums[dq[-1]] <= nums[i]:
dq.pop()
dq.append(i)
if k-1 <= i:
ret.append(nums[dq[0]])
return ret