title: counting number of swaps in insertion sort
body: <p>In the problem given <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4e90477dbd22b" rel="nofollow noreferrer">here</a>,  i have to count total no. of swaps required while sorting an array using insertion sort.<br />
  here is my approach</p>
  <pre><code>#include &lt;stdio.h&gt;
  int main()
  {
      int t, N, swaps, temp, i, j;
      scanf(&quot;%d&quot;, &amp;t);
  
      while(t--){
          scanf(&quot;%d&quot;, &amp;N);
          
          int arr[N];
          swaps = 0;
      
          for(i=0; i&lt;N; ++i){
  
              scanf(&quot;%d&quot;, &amp;temp);
  
              j=i;
              while(j&gt;0 &amp;&amp; arr[j-1] &gt; temp){
                  arr[j] = arr[j-1];
                  ++swaps;
                  --j;
              }
  
              arr[j] = temp;
          }
          printf(&quot;%d\n&quot;, swaps);
      }
  
      return 0;
  }
  </code></pre>
  <p>but, this soln is giving time limit exceeded.</p>
  <p>How can i make it more fast?<br />
  and, what are the other better solutions of this problem?</p>