title: Find if in an array there are at least once all the numbers from 1 to K
body: <p>Yesterday I did a test on C++ for an interview and I had to find bugs in the following code.</p>
  
  <p>The algorithm takes in input a vector of integer sorted in a non-decreasing order and an integer K. The algorithm returns true if the vector contains only and all the numbers between 1 and k at least once, and false otherwise:</p>
  
  <p>([1,1,2,3,3,4],4) --> true</p>
  
  <p>([1,1,3],3) --> false</p>
  
  <p>This was the implementation:</p>
  
  <pre><code>bool algorithm(vector&lt;int&gt; &amp;A, int k)
  {
     n = A.size();
     for(int i = 0; i &lt; n-1; i++)
     {
        if(A[i]+1 &lt; A[i+1])
           return false;
     }
     if(A[0] != 1 &amp;&amp; A[n-1] != K)
     {
        return false;
     }
     else
     {
        return true;
     }
  }
  </code></pre>
  
  <p>I wasn't able to find bug/bugs. Could someone tell me where is/are the bug/s in this code?</p>