One test case not working

what changes should i make so that both test cases work

Hi @akshay9009,share your code here.

import java.util.*;
class Main {
public static void main(String args[]) {
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int arr[]=new int[n];
for(int i=0;i<arr.length;i++){
arr[i]=scan.nextInt();
}
Stack s=new Stack<>();
for(int i=0;i<arr.length;i++){
while(!s.isEmpty()&& arr[i]>s.peek()){
int rv=s.pop();
System.out.print(arr[i]+" ");
}
s.push(arr[i]);

    }
    if(!s.isEmpty()){
        System.out.print(-1);
        s.pop();
    }
    
}

}

Hi your code dooesnot for work 5
4 4 4 4 4
it prints only one time -1 but should print 5 times -1.
so after the loop where you have written if write while.

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.