For this Question: Given an array A of size N, the task is to find the nearest greater element G[i] for every element of A[i] such that the element has index greater than i, If no such element exists, output -1.
More formally:
G[i] for an element A[i] = an element A[j] such that 
    j is minimum possible AND 
    j > i AND
    A[j] > A[i]Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A.

Constraints:
1 <= N <= 10^5
1 <= Ai <= 10^9For each test case, print the next greater element for each array element separated by space in order.Sample Input
4
1 3 2 4

Sample Output
3 4 4 -1

Sample Input
4
4 3 2 1

Sample Output
-1 -1 -1 -1, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
	public static void main (String[] args) {
                      // Your code here

        Scanner sc = new Scanner(System.in);
        int arrSize = sc.nextInt();

        int arr[] = new int[arrSize];
        for(int i = 0; i < arrSize; i++)
           arr[i] = sc.nextInt();
           
        nextLarger(arr, arrSize);
	}
    static void nextLarger(int arr[], int arrSize)
    {
            Stack<Integer> s = new Stack<>();
			int a = 0; 
			for(int i=arrSize-1;i>=0;i--)
			{
				a= arr[i];

				while(!(s.empty() == true)){
						if(s.peek()>a){break;}
					s.pop();
				}
				if(s.empty() == true){arr[i]=-1;}
				else{arr[i]=s.peek();}
				s.push(a);
		     }

			for(int i=0;i<arrSize;i++)
			{
				System.out.print(arr[i]+" ");
	        }
    }



}, In this Programming Language: Java, Now tell me if this Code is compilable or not?