10 lines 🚀 Monotonic Stack | One pass | Dummy node technique
Intuition\n Describe your approach to solving the problem. \nUsing dummy nodes to avoid edge cases.\n\n# Complexity\n- Time complexity: O(n)\n Add your time com
# Intuition\n<!-- Describe your approach to solving the problem. -->\nUsing dummy nodes to avoid edge cases.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def largestRectangleArea(self, heights: List[int]) -> int:\n        stack = [-1] # dummy index, to prevent stack from empty error\n        heights.append(0) # dummy node in the tail\n        max_area = 0\n        for i, cur_height in enumerate(heights):\n            while stack and heights[stack[-1]] > cur_height:\n                height = heights[stack.pop()]\n                width = i - stack[-1] - 1\n                max_area = max(max_area, width * height)\n            stack.append(i)\n        return max_area\n```
['Monotonic Stack', 'Python3']