In the question next greater element

import java.util.*;

public class Main {

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();
    Stack<Integer> s = new Stack<>();
    s.push(0);
    int[] ans = new int[n];
    for(int i=1;i<n;i++){
        while (!s.isEmpty() && arr[i]>arr[s.peek()]) {                
           ans[s.pop()]=arr[i];
        }
        s.push(i);
    }
    while(!s.isEmpty()){
        ans[s.pop()]=-1;
    }
    for (int a : ans)
        System.out.print(a + " ");
    System.out.println();
}

}

what is wrong with this code , cannot pass all test cases

okay I will look into it

Sir??? When will you have the answer for my query??

had some other doubts to take care of, what all test cases are it passing?

2nd and 3rd passing
1st wrong answer

Input in first test case is
4
8 2 3 6
correct output is
-1 3 6 8
Dry run your code on this

But the last element which is 6 have no next greater element so it will be -1 or for the output you said will be for circular array, which is not mentioned

circular queue is mentioned in the question