import java . util . *;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n =sc.nextInt();
int [] a= new int[n];
for(int i=0;i<a.length;i++) {
a[i]=sc.nextInt();
}
Stack stack = new Stack<>(); // generic function
for (int i = 0; i < a.length; i++) {
while (!stack.isEmpty() && a[i] > stack.peek()) {
int rv = stack.pop();
System.out.print(a[i]+" ");
}
stack.push(i); // Corrected this line
}
while (!stack.isEmpty()) {
int rv = stack.pop();
System.out.print( "-1 ");
}
}
}
what’s wrong mistake i have done in this programme only one test are passing.