public static int getMaxArea(int[] histogram) {
        LinkedList<Integer> stack = new LinkedList<>();
        int maxArea = 0;
        int i = 0;

        while(i < histogram.length) {
            if(stack.isEmpty() || histogram[stack.peek()] < histogram[i]) {
                stack.push(i++);
            } else {
                int stackTop = stack.peek();
                stack.pop();
                int stackTopArea = histogram[stackTop] * (stack.isEmpty()? i: i - stack.peek() -1);
                maxArea = Math.max(maxArea, stackTopArea);
            }
        }

        while(!stack.isEmpty()) {
            int stackTop = stack.peek();
            stack.pop();
            int stackTopArea = histogram[stackTop] * (stack.isEmpty()? i: i - stack.peek() -1);
            maxArea = Math.max(maxArea, stackTopArea);
        }

        return maxArea ;
    }