title: no getting output for the following c++ code problem on hackerearth
body: <p>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. <a href="https://www.hackerearth.com/practice/data-structures/stacks/basics-of-stacks/practice-problems/algorithm/a-game-of-numbers-1-5d3a8cb3/" rel="nofollow noreferrer">https://www.hackerearth.com/practice/data-structures/stacks/basics-of-stacks/practice-problems/algorithm/a-game-of-numbers-1-5d3a8cb3/</a>.   </p>
  
  <p>i was not getting output </p>
  
  <pre><code>#include&lt;iostream&gt;
  
  using namespace std;
  
  int main()
  
  { int l,n,j;
      int a[n],f[n],g[n];
  
      cin&gt;&gt;n;
      l=n;
  
      for(int i=n-1;i&gt;=0;i--)
      {
          cin&gt;&gt;a[i];
      }
  
      for(int i=n-1;i&gt;=0;i--)
      {
          for(j=i-1;j&gt;=0;j--)
          {
             if(a[j] &gt; a[i])
             {
               f[l-i] = l-j;
             }
             else
             {
               f[l-i] = -1;
             }
          }
      }
  
      for(int i=n-1;i&gt;=0;i--)
      {
          for(j=i-1;j&gt;=0;j--)
          {
             if(g[j] &lt; g[i])
             {
               g[l-i] = l-j;
             }
             else
             {
               g[l-i] = -1;    
             }
          }
      }
  
      for(int i=0;i&lt;l;i++)
      {
          if (f[i]== -1)
          {
              cout&lt;&lt;-1;
          }
          else
          {
              cout&lt;&lt; a[g[f[i]]];
          }
      }
  }
  </code></pre>