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 janusztracz73ms
#znajduje wszystkie kombinacje liczb obok siebie i znajduje minimalna wspolna wartosc
def largest_histogram(h):
lista = []
odwrocona = reversed(h)
print(odwrocona)
print(len(h))
if len(h) == 1:
return h[0]
for x in range(len(h)):
for z in range(len(h), x+1,-1):
lista.append(h[x:z])
print(lista)
lista2 = []
for y in lista:
lista2.append(min(y) * len(y))
print(lista2)
print(max(lista2))
return(max(lista2))
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!")
Oct. 30, 2016