Question DSA-QUE-0062
HardWhat is the output of this code?
from collections import deque
def first_neg(a, k):
q, out = deque(), []
for i, x in enumerate(a):
if x < 0:
q.append(i)
if q and q[0] <= i - k:
q.popleft()
if i >= k - 1:
out.append(a[q[0]] if q else 0)
return out
print(first_neg([12, -1, -7, 8, -15, 30, 16, 28], 3))
- A.
[-1, -1, -7, -15, -15, 30]
- B.
[-1, -7, -15, -15, 0, 0]
- C.
[-1, -1, -7, -15, -15, 0]
- D.
[12, -1, -7, 8, -15, 30]
Sign up free to see the answer and a step-by-step explanation.