For this Question: Given an integer array A of size N. Another array B is defined as:
B[i] = A[j] such that j > i and A[j] < A[i]. If there does not exist any index j satisfying the above conditions then B[i] = -1. 
Find the array B.The first line contains an integer N.
The next line contains N space-separated integers denoting elements of the array.

<b>Constraints:</b>
1 &le; N &le; 10<sup>5</sup>
1 &le; Ai &le; 10<sup>5</sup>Print N space separated integers denoting the elements of array B.Sample Input 1:
4
10 2 5 3

Output 
2 -1 3 -1

Explanation:
Next element smaller than 10 is 2.
There are no elements after 2 that are less than 2.
Next element smaller than 5 is 3.
There are no elements after 3.

Sample Input 2:
2
1 2

Output 
-1 -1

Explanation:
There are no elements after 1 which is less than 1 and there are no elements after 2. , 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 n=sc.nextInt();
	long a[]=new long[n];
	for(int i=0;i<n;i++)
	a[i]=sc.nextInt();

	long res[]=new long[n];
    Arrays.fill(res,-1);
	Stack<Integer> stack=new Stack<>();
	stack.push(0);
	for(int i=1;i<n;i++){
		while(!stack.isEmpty() && a[i] < a[stack.peek()]){
			res[stack.pop()]=a[i];
		}
		stack.push(i);
	}
	for(int k=0;k<n;k++){
	System.out.print(res[k]+" ");
	}
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?