title: largest number of dinosaurs that were ever alive
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/14646668/algorthim-to-solve-find-max-no-at-a-time">algorthim to solve find max no at a time</a>  </p>
  </blockquote>
  
  
  
  <p>We are given an array of 2n integers wherein each pair in this array of integers represents the year of birth and the year of death of a dinosaurs respectively. The range of valid years we want to consider is [-100000 to 2005]. For example, if the input was:</p>
  
  <p>-80000 -79950 20 70 22 60 58 65 1950 2004</p>
  
  <p>it would mean that the first dinosaur had a birth year of –80000 and an year of death of –79950 respectively. Similarly the second dinosaur lived from 20 to 70 and so on and so forth.</p>
  
  <p>We would like to know the largest number of dinosaurs that were ever alive at one time. Write a method to compute this, given the above array of 2n integers.</p>
  
  <p>Here's what I've tried so far:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include &lt;stddef.h&gt;
  
  static void insertion_sort(int *a, const size_t n) 
  {
      size_t i, j;
      int value;
      for (i = 1; i &lt; n; i++) {
          value = a[i];
          for (j = i; j &gt; 0 &amp;&amp; value &lt; a[j - 1]; j--) {
              a[j] = a[j - 1];
          }
          a[j] = value;
      }
  }
  
  int  main(){
      int arr[10]={-80000,-79950,20,70,22,60,58,65,1950,2004};
      int strt[5],end[5];
      int bal[5];
      int i,j,k,l,m,length;
      l=0;
      m=0;
  
      for (i=0; i&lt;10; i++){
          //printf("i = %2d arr[i] = %2d\n", i, arr[i]);
          if(i%2==0) {
              strt[l]=arr[i];
              l++;
          } else {
              end[m]=arr[i];
              m++;
          }
      }
  
      insertion_sort(strt, sizeof strt / sizeof strt[0]);
      insertion_sort(end, sizeof end / sizeof end[0]);
      k=sizeof(end)/sizeof(int);
  
      for(j=0;j&lt;5;j++) {
          bal[i]=strt[i]-end[k-1];
          k--;
      }
      length=sizeof bal / sizeof bal[0];
      insertion_sort(bal, sizeof bal / sizeof bal[0]);
      printf("answer is = %2d",bal[length-1]);
  }
  </code></pre>