title: Terminated due to timeout: Where is the scope of optimization?
body: <p>I was solving a problem in Hackerrank which is as shown below:</p>
  <blockquote>
  <p>Given an array <code>a</code>  of  <code>n</code> integers and a number <code>d</code>, , perform <code>d</code>
  left rotations on the array. Return the updated array to be printed as
  a single line of space-separated integers.</p>
  </blockquote>
  <p>Here is my very simple solution:</p>
  <pre><code>#include&lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      int n,d;
  
      cin&gt;&gt;n&gt;&gt;d;
  
      int arr[n];
  
      for(int i = 0; i &lt; n; i++)
      cin&gt;&gt; arr[i];
  
      for(int i = 0; i &lt; d; i++)
      for(int j = 0; j &lt; n - 1; j++)
      {
          arr[j] = arr[j] + arr[j + 1];
          arr[j + 1] = arr[j] - arr[j + 1];
          arr[j] = arr[j] - arr[j + 1];
  
      }
  
      for(int i = 0; i &lt; n; i++)
      cout&lt;&lt;arr[i]&lt;&lt;&quot; &quot;;
  }
  </code></pre>
  <p>But it still throws an error saying:</p>
  <p><code>Terminated due to timeout :(</code></p>
  <p>What improvements can I make in this script? Any suggestion will be really helpful. Thanks in advance.</p>