Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Largest Rectangle in a Histogram by PawlakBartosz43
def largest_histogram(histogram):
increasing, area, i = [], 0, 0
while(i <= len(histogram)):
if not increasing or (i < len(histogram) and histogram[i] > histogram[increasing[-1]]):
increasing.append(i)
i += 1
else:
last = increasing.pop()
if not increasing:
area = max(area, histogram[last] * i)
else:
area = max(area, histogram[last] * (i - increasing[-1] - 1))
return(area)
Jan. 3, 2017