title: A C++ Program which works fine in online compilers and linux operating systems, but not on Windows
body: <p>While compiling a problem:<br />
  <a href="https://practice.geeksforgeeks.org/problems/first-repeating-element4018/1//" rel="nofollow noreferrer">Geeks For Geeks: First Repeating Element</a> on a Windows operating system I noticed that I was not getting any output for my solution. But when I compiled the same code on a Linux operating system and on online compilers, it worked absolutely fine without producing any errors.</p>
  <p>Code:</p>
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  int main() {
  
      int n;
      cin&gt;&gt;n;
      int arr[n];
  
      for(int i=0; i &lt;n; i++) {
          cin&gt;&gt;arr[i];
      }
  
      int size= 1e6+1; // WA on windows
      int A[size];
      int min_index=INT_MAX;
  
      for(int i=0; i&lt;size; i++) {
          A[i]=-1;
      }
  
      for(int i=0; i&lt;n; i++) {
          if(A[arr[i]]!=-1)
              min_index=min(min_index, A[arr[i]]);
          else
              A[arr[i]]=i;
      }
  
      if(min_index==INT_MAX) 
          cout&lt;&lt;&quot;-1&quot;;
      else
          cout&lt;&lt; min_index+1;
  
      return 0;
  }
  </code></pre>
  <p>Sample Test Case:</p>
  <pre><code>7
  1 5 3 4 3 5 6
  </code></pre>
  <p>Expected output:</p>
  <pre><code>2
  </code></pre>
  <p>Output on Windows:
  <a href="https://i.stack.imgur.com/d6cA9.png" rel="nofollow noreferrer">Screenshot</a></p>
  <p>Output on Linux:
  <a href="https://i.stack.imgur.com/Rt2NA.png" rel="nofollow noreferrer">Screenshot</a></p>
  <p>Explanation for the program from line 14 of code:</p>
  <p>I created an array <code>A</code> of size <code>1e6+1</code> to store value <code>i</code> on its <code>arr[i]</code>th index.<br />
  Array <code>A</code> was earlier initialized with value <code>-1</code>. It runs for <code>n</code> number of times and variable <code>min_index</code> stores the index of the least repeating number from the array <code>arr</code>.<br />
  After initializing smaller values of array <code>int size = 10</code> and using very small test cases(also max value of arr[i] is lesser than size of <code>A</code>; I realize that the program runs perfectly in Windows.</p>
  <p>As far as I understand, Windows might be having some trouble intializing arrays of such large length (Please correct me if I'm wrong). But why isn't it the same in the case of Linux?</p>