title: Codility - function alteration
body: <p>I cam across this codility test, the problem was to spot a bug in the function and adjust it so that it worked properly.</p>
  
  <p>The array passed to the function is {1,3,3} and K =2.  The function is supposed to return false if K is not found in the array, but it is returning true.  You were only allowed to alter 2 lines of code.</p>
  
  <pre><code>public static bool solution(int[] A, int K)
      {
  
          int n = A.Length;
          for (int i = 0; i &lt; A.Length - 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>In normal circumstances I would just rewrite the function given that I know what it is supposed to do:</p>
  
  <pre><code>public static bool solution(int[] A, int K)
      {
          int n = A.Length;
          int count = 0;
          for (int i = 0; i &lt; A.Length - 1; i++)
          {
              if (A[i] == K)
              {
                  count++;
              }
          }
          if (count == 0)
              return false;
          else
              return true;
      }
  </code></pre>