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 DroG
def largest_histogram(histogram):
h=histogram
maxkybikov=[]
i=0
while i < len(h):
j=1
while j<=h[i]:
stolb = 1
if i>0:
x = i-1
while x >= 0:
if h[x]>=j:
stolb+=1
else: break
x-=1
if i<(len(h)-1):
x = i+1
while x <= (len(h)-1):
if h[x]>=j:
stolb+=1
else: break
x+=1
kybikov=stolb*j
maxkybikov.append(kybikov)
j+=1
i+=1
print ('maxkybikov = ',maxkybikov)
return max(maxkybikov)
if __name__ == "__main__":
#These "asserts" using only for self-checking and not necessary for auto-testing
assert largest_histogram([5]) == 5, "one is always the biggest"
assert largest_histogram([5, 3]) == 6, "two are smallest X 2"
assert largest_histogram([1, 1, 4, 1]) == 4, "vertical"
assert largest_histogram([1, 1, 3, 1]) == 4, "horizontal"
assert largest_histogram([2, 1, 4, 5, 1, 3, 3]) == 8, "complex"
print("Done! Go check it!")
Nov. 19, 2016