C# Solution
\npublic class Solution \n{\n    public int LargestRectangleArea(int[] heights) \n    {\n        int n = heights.Length, max = 0;\n        var stack = new Stack
```\npublic class Solution \n{\n    public int LargestRectangleArea(int[] heights) \n    {\n        int n = heights.Length, max = 0;\n        var stack = new Stack<int>();\n        for(int i = 0; i <= n; i++)\n        {\n            var height = i < n ? heights[i] : 0;\n            while(stack.Count != 0 && heights[stack.Peek()] > height)\n            {\n                var currHeight = heights[stack.Pop()];\n                var prevIndex = stack.Count == 0 ? -1 : stack.Peek();\n                max = Math.Max(max, currHeight * (i - 1 - prevIndex));\n            }\n            stack.Push(i);\n        }\n        \n        return max;\n    }\n}\n```
[]