Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Check each floor solution in 3rd party category for Largest Rectangle in a Histogram by V.Shkaberda
from itertools import groupby
import numpy as np
def largest_histogram(h):
# create matrix
np_h = np.zeros((max(h), len(h)))
# make a histogram from it
for i, x in enumerate(h):
np_h[:x, i] = 1
# find max width for each floor
w = np.apply_along_axis(lambda row: max(sum(1 for _ in group)
for key, group
in groupby(row) if key), 1, np_h)
# multiply by height
area = w * np.arange(1, max(h) + 1, 1)
# voilĂ
return int(max(area))
Oct. 27, 2018