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