Question DSA-STK-0062
HardWhat is the output of this code?
a = [2, 1, 2, 4, 3]
res, st = [-1] * len(a), []
for i in range(2 * len(a) - 1, -1, -1):
x = a[i % len(a)]
while st and st[-1] <= x:
st.pop()
if i < len(a):
res[i] = st[-1] if st else -1
st.append(x)
print(res)
- A.
[2, 2, 4, -1, 4]
- B.
[-1, 2, 4, -1, 4]
- C.
Sign up free to see the answer and a step-by-step explanation.