import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    public static void check(int arr[], int day[]){
        Stack<Integer> st=new Stack<>();
        st.push(0);
        day[0]=1;
        for(int i=1;i<arr.length;i++){
            while(!st.isEmpty() && arr[st.peek()]<=arr[i])
                st.pop();
            day[i]=(st.isEmpty()? i+1 : i-st.peek());
            st.push(i);
        }
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        int arr [] =new int[n];
        for(int i =0;i<n;i++){
            arr[i] = sc.nextInt();
        }
        int day []=new int[n];
        check(arr, day);
        System.out.print(Arrays.toString(day));
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: