class Solution {
    public int calculateArea(int[] heights, int start, int end) {
        Deque<Integer> stack = new ArrayDeque<>();
        stack.push(-1);
        int n = heights.length;
        int maxArea = 0;
        
        for (int i = 0; i < n; i++) {
            while ((stack.peek() != -1)
                    && (heights[stack.peek()] >= heights[i])) {
                int currentHeight = heights[stack.pop()];
                int currentWidth = i - stack.peek() - 1;
                maxArea = Math.max(maxArea, currentHeight * currentWidth);
            }
            
            stack.push(i);
        }
        
        while (stack.peek() != -1) {
            int currentHeight = heights[stack.pop()];
            int currentWidth = n - stack.peek() - 1;
            maxArea = Math.max(maxArea, currentHeight * currentWidth);
        }
        
        return maxArea;
    }
}

@@ -1,21 +1,108 @@
-class Solution
+package org.pilgrim.leetcode.y2022;%0A%0Aimport java.util.Stack;%0A%0Apublic class LargestRectangleHistogram
  %7B%0A
+%0A
     
@@ -112,16 +112,144 @@
 lic int 
+largestRectangleArea(int%5B%5D heights) %7B%0A        return this.calculateArea(heights, 0, heights.length - 1);%0A    %7D%0A%0A    private int 
 calculat
@@ -299,21 +299,21 @@
         
-Deque
+Stack
 %3CInteger
@@ -330,18 +330,13 @@
 new 
-ArrayDeque
+Stack
 %3C%3E()
@@ -418,24 +418,16 @@
 ea = 0;%0A
-        
 %0A       
@@ -500,28 +500,8 @@
  -1)
-%0A                   
  && 
@@ -745,28 +745,16 @@
       %7D%0A
-            
 %0A       
@@ -779,32 +779,24 @@
 ;%0A        %7D%0A
-        
 %0A        whi
@@ -1009,24 +1009,16 @@
       %7D%0A
-        
 %0A       
@@ -1040,10 +1040,324 @@
 ;%0A    %7D%0A
+    %0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D histogram = %7B1,2,3,4,2,10%7D;%0A        LargestRectangleHistogram largestRectangleHistogram = new LargestRectangleHistogram();%0A        %0A        int area = largestRectangleHistogram.largestRectangleArea(histogram);%0A        System.out.println(area);%0A    %7D%0A
 %7D%0A

update Largest rectangle histogram