Question DSA-TP-0018
HardWhat is the output of this code?
from collections import deque
a, k = [1, 3, -1, -3, 5, 3, 6, 7], 3
dq, out = deque(), []
for i, x in enumerate(a):
while dq and a[dq[-1]] <= x:
dq.pop()
dq.append(i)
if dq[0] <= i - k:
dq.popleft()
if i >= k - 1:
out.append(a[dq[0]])
print(out)
- A.
[7, 6, 5, 5, 3, 3]
- B.
[3, 5, 5, 6, 7, 7]
- C.
Sign up free to see the answer and a step-by-step explanation.