Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
\,,/(^_^)\,,/ solution in Clear category for Largest Rectangle in a Histogram by vmiimu
def largest_histogram(h):
stk, mx, i = list(), 0, 0
while i < len(h):
if not stk or h[stk[-1]] <= h[i]:
stk.append(i)
i += 1
else:
cmax = stk.pop()
area = h[cmax] * (i if not stk else i-stk[-1]-1)
mx = max(mx, area)
while stk:
cmax = stk.pop()
area = h[cmax] * (i if not stk else i-stk[-1]-1)
mx = max(mx, area)
return mx
Nov. 26, 2018