• + 1 comment

    // Please tell why error test cases go wrong on submit? public static long largestRectangle(List h) { int x = h.size() + 1; Stack stack = new Stack<>(); Collections.sort(h);

        for(int i = h.size() - 1; i >= 0; i--){
            long a = (long) h.get(i) * (x - (i + 1));
            stack.push(a);
        }
    
        long max = Long.MIN_VALUE;
        // Iterate through the stack
        while (!stack.isEmpty()) {
            long num = stack.pop();      
            if (num > max) {
                max = num;     
            }
        }
        return max;
    }
    

    }