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