Largest Rectangle

  • + 0 comments

    Python, recursive, not O(N) but short.

    def largestRectangle(h):
        if h:
            i = min(range(len(h)), key=h.__getitem__)
            return max(h[i] * len(h), largestRectangle(h[:i]), largestRectangle(h[i+1:]))
        return 0