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