title: Least frequent number in an array
body: <p>I'm having problems with this function . I've tested for example this input </p>
  
  <blockquote>
    <p>Input : 2 2 3 4 4</p>
    
    <p>Output : 3</p>
  </blockquote>
  
  <p>It works fine so far. But when I have two or more numbers who are in this particularly situation:</p>
  
  <blockquote>
    <p>Input : 1 3 3 4</p>
    
    <p>Output : 4</p>
  </blockquote>
  
  <p>I keep getting the number with the largest index. What I really wanted was  this Output in that situation ( number with the smallest index ) :</p>
  
  <blockquote>
    <p>Output : 1</p>
  </blockquote>
  
  <p><strong>This is my code :</strong></p>
  
  <pre><code>int leastFreq (int v[] , int size)
  {
    int i ;
    int count = 0;
    int repetitions = 0;
    int lower;
  
    for ( i = 0 ; i &lt; size ; i ++)
    {
     if (v[i] != v[i+1])
     { 
       count --;
          if ( count &lt; repetitions)
          {
            repetitions = count;
            lower = v[i];
          }
     }
     else 
     { count = 0 ;}  
    }
     return lower;
  }
  </code></pre>
  
  <p><strong>How can I fix this problem ?</strong>
  <strong>(This is an sorted array)</strong></p>