title: Cant figure out the testcase where I am getting segmentation fault?
body: <p>I am getting segmentation fault for some unknown test case and I am unable to resolve it.
  It runs for most of the cases. I only want to know in which case I am getting segmentation fault.
  The code is written for the Question Maximim Rectangular Area in a Histogram. You can check this question here: <a href="https://practice.geeksforgeeks.org/problems/maximum-rectangular-area-in-a-histogram-1587115620/1#" rel="nofollow noreferrer">https://practice.geeksforgeeks.org/problems/maximum-rectangular-area-in-a-histogram-1587115620/1#</a></p>
  <p>Below is the code:</p>
  <pre><code> long long getMaxArea(long long arr[], int n)
      {
          int nsl[n];
          int nsr[n];
          stack&lt;int&gt;s;
          // nsl
          for(int i=0;i&lt;n;i++)
          {
              if(i==0)
              {
                  nsl[i]=-1;
                  s.push(i);
              }
              else{
                  while(!s.empty())
                  {
                      if(arr[s.top()]&lt;arr[i])
                      break;
                      s.pop();
                  }
                  if(s.empty())
                  nsl[i]=-1;
                  else
                  nsl[i]=s.top();
                  s.push(i);
              }
          }
          stack&lt;int&gt;st;
          // nsr
          for(int i=n-1;i&gt;=0;i--)
          {
              if(i==n-1)
              {
                  nsr[i]=n;
                  st.push(i);
              }
              else{
                  while(!st.empty())
                  {
                      if(arr[st.top()]&lt;arr[i])
                      break;
                      st.pop();
                  }
                  if(st.empty())
                  nsr[i]=n;
                  else
                  nsr[i]=st.top();
                  st.push(i);
              }
          }
          long long ans=0;
          for(int i=0;i&lt;n;i++)
          ans=max(ans,arr[i]*(nsr[i]-nsl[i]-1));
          return ans;
      }
  </code></pre>