fork download
  1. def print_max(nums, n, k):
  2. from collections import deque
  3. q = deque()
  4. res = []
  5.  
  6. for i in range(0, len(nums)):
  7. cur = nums[i]
  8. while len(q) > 0 and cur > nums[q[-1]]:
  9. q.pop()
  10.  
  11. q.append(i)
  12.  
  13. if q[0] == i-k:
  14. q.popleft()
  15.  
  16. if i >= k-1:
  17. res.append(nums[q[0]])
  18.  
  19.  
  20. print(res)
  21.  
  22.  
  23.  
Success #stdin #stdout 0.04s 9488KB
stdin
Standard input is empty
stdout
Standard output is empty