HISTOGRAM

Added: 2026-03-28 06:50:10

Question Image

HISTOGRAM

Answer

✏️ Edit
s=input().strip()
h=list(map(int,s[1:-1].split(','))) if s[0]=='[' else list(map(int,s.split()))
h+=[0]
st=[];r=0
for i,x in enumerate(h):
    while st and h[st[-1]]>x:
        H=h[st.pop()]
        W=i if not st else i-st[-1]-1
        r=max(r,H*W)
    st.append(i)
print(r)