can anyone please solve the error i am facing in this problem please can you try to figure it out ? i will provide link for this question below. https://www.hackerearth.com/practice/data-structures/stacks/basics-of-stacks/practice-problems/algorithm/a-game-of-numbers-1-5d3a8cb3/.
i was not getting output
#include<iostream>
using namespace std;
int main()
{ int l,n,j;
int a[n],f[n],g[n];
cin>>n;
l=n;
for(int i=n-1;i>=0;i--)
{
cin>>a[i];
}
for(int i=n-1;i>=0;i--)
{
for(j=i-1;j>=0;j--)
{
if(a[j] > a[i])
{
f[l-i] = l-j;
}
else
{
f[l-i] = -1;
}
}
}
for(int i=n-1;i>=0;i--)
{
for(j=i-1;j>=0;j--)
{
if(g[j] < g[i])
{
g[l-i] = l-j;
}
else
{
g[l-i] = -1;
}
}
}
for(int i=0;i<l;i++)
{
if (f[i]== -1)
{
cout<<-1;
}
else
{
cout<< a[g[f[i]]];
}
}
}