Largest Rectangle

  • + 0 comments

    Same as LeetCodes "Largest Rectangle in Histogram" https://leetcode.com/problems/largest-rectangle-in-histogram/submissions/1092315461/

        stack = [-1]
        h.append(0)
        maxA = 0
        for i in range(len(h)):
            while h[i] < h[stack[-1]]:
                height = h[stack.pop()]
                width = i - stack[-1] -1
                if height * width > maxA:
                    maxA = height * width
            stack.append(i)
        return maxA