Question DSA-STK-0017
HardWhat is the output of this code?
t = [73, 74, 75, 71, 69, 72, 76, 73]
res = [0] * len(t)
st = []
for i, x in enumerate(t):
while st and t[st[-1]] < x:
j = st.pop()
res[j] = i - j
st.append(i)
print(res)
- A.
[0, 0, 4, 2, 1, 1, 0, 0]
- B.
[1, 1, 4, 2, 1, 1, 0, 0]
- C.
Sign up free to see the answer and a step-by-step explanation.