title: minimum steps required to make array of integers contiguous
body: <p>given a sorted array of distinct integers, what is the minimum number of steps required to make the integers contiguous? Here the condition is that: in a step , only one element can be changed and can be either increased or decreased by 1 . For example, if we have <code>2,4,5,6</code> then '2' can be made '3' thus making the elements contiguous(<code>3,4,5,6</code>) .Hence the minimum steps here is 1 . Similarly for the array: <code>2,4,5,8</code>:</p>
  
  <ul>
  <li>Step 1: '2' can be made '3'  </li>
  <li>Step 2: '8' can be made '7'</li>
  <li>Step 3: '7' can be made '6'</li>
  </ul>
  
  <p>Thus the sequence now is <code>3,4,5,6</code> and the number of steps is 3.</p>
  
  <p>I tried as follows but am not sure if its correct?</p>
  
  <pre><code>    //n is the number of elements in array a
      int count=a[n-1]-a[0]-1;
      for(i=1;i&lt;=n-2;i++)
      {
          count--;
      }
      printf("%d\n",count);
  </code></pre>
  
  <p>Thanks.</p>