Easy-to-understand 92ms Python solution, linear time and space.
class Solution(object):\n    # Helper function calculating how far each bar can be extended to the right.\n    def calmax(self, height):\n        stack = []\n  
    class Solution(object):\n    # Helper function calculating how far each bar can be extended to the right.\n    def calmax(self, height):\n        stack = []\n        n = len(height)\n        rec = [0] * n\n        for i in xrange(len(height)):\n            while len(stack) > 0 and height[stack[-1]] > height[i]:\n                top = stack.pop()\n                rec[top] = i\n            stack.append(i)\n        for i in stack:\n            rec[i] = n\n        return rec\n    def largestRectangleArea(self, height):\n        # How far can each bar be extended to the right?\n        rec1 = self.calmax(height)\n        # How far can each bar be extended to the left?\n        rec2 = self.calmax(height[::-1])[::-1]\n        maxa = 0\n        n = len(height)\n        for i in xrange(n):\n            # Add the left and right part together\n            new = height[i] * (rec1[i] + rec2[i] - n)\n            maxa = max(new, maxa)\n        return maxa\n\nThis solution can be made faster. But who cares if the complexity is still \\Theta(n)?
[]