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: #include <bits/stdc++.h>
using namespace std;

int main(){

int n;
cin>>n;
stack <long long > s;
long long a,b[n];
for(int i=0;i<n;i++){
        cin>>b[i];}
        for(int i=n-1;i>=0;i--){
            a=b[i];

    while(!(s.empty())){
            if(s.top()>a){break;}
        s.pop();
    }
    if(s.empty()){b[i]=-1;}
    else{b[i]=s.top();}
    s.push(a);
}
for(int i=0;i<n;i++){
    cout<<b[i]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?