Skip to content

Instantly share code, notes, and snippets.

@Youngestdev
Created July 25, 2020 13:36
Show Gist options
  • Save Youngestdev/57c6a2b33cc9f944694c5112ca81a509 to your computer and use it in GitHub Desktop.
Save Youngestdev/57c6a2b33cc9f944694c5112ca81a509 to your computer and use it in GitHub Desktop.
q, res = deque(), []
for i, v in enumerate(nums):
while q and v > nums[q[-1]]:
q.pop()
while len(q) < min(i+1,k):
q.append(i)
if i >= k-1:
res.append(nums[q.popleft()])
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment