Question DSA-STK-0045
MediumWhat is the output of this code?
h = [2, 1, 5, 6, 2, 3]
st, best = [], 0
for i, x in enumerate(h + [0]):
start = i
while st and st[-1][1] > x:
j, y = st.pop()
best = max(best, y * (i - j))
start = j
st.append((start, x))
print(best)
- A.
6
- B.
8
- C.
Sign up free to see the answer and a step-by-step explanation.