def maxSlidingWindow(nums, k: int): if not nums:return [] window,res=[],[] for i,a in enumerate(nums): if i>=k and window[0]<=i-k: window.pop(0) while window and nums[window[-1]]<=a: window.pop(-1) window.append(i) if i>=k-1: res.append(nums[window[0]]) return res