My Code Shows Wrong Error

I have tried for multiple test cases It gives correct ooutput but when i submit it shows wrong answer in all test cases.Please Help Sir/Ma’am

@Devforlife07
send me your code then only i would be able to help

import java.util.*;

class histogram {
static Stack st = new Stack<>();
static Scanner sc = new Scanner(System.in);

public static void main(String[] args) {
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
        a[i] = sc.nextInt();
    int ans = cal(a);
    System.out.println(ans);
}

public static int cal(int[] a) {
    int maxArea = 0;
    int i = 0;
    while (i < a.length) {
        if (st.isEmpty() || a[st.peek()] <= a[i]) {
            st.push(i++);
        } else {
            int top = st.peek();
            st.pop();
            int area = st.isEmpty() ? a[top] * i : a[top] * (i - st.peek() - 1);
            if (area > maxArea)
                maxArea = area;

        }
    }
    while (!st.isEmpty()) {
        int top = st.peek();
        st.pop();
        int area = st.isEmpty() ? a[top] * i : (a[top] * (i - st.peek() - 1));
        if (area > maxArea)
            maxArea = area;
    }

    return maxArea;
}

}

@Devforlife07
hello please check your inbox and mark your doubt as resolved if you are satisfied with my response

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.