title: Wrong answer in task - mistake in algorithm
body: <p>I doing my homework (first sorry for english). </p>
  
  <p>Consider N coins aligned in a row. Each coin is showing either heads or tails. The adjacency of these coins is the number of pairs of adjacent coinst showing the same face.Return the maximum possible adjacency that can be obtained by reversing one coin, one of the coinst must be reversed</p>
  
  <p>for example i have</p>
  
  <pre><code>1 1 0 1 0 0 
  </code></pre>
  
  <p>and after change <code>third</code> we get <code>1 1 1 1 0 0</code> so we have 4 pairs.</p>
  
  <p>But my code doesn't work for example</p>
  
  <pre><code>1 1 
  </code></pre>
  
  <p>I should get <code>0</code> but get <code>1</code></p>
  
  <pre><code>  public static void main(String[] args) {
      int[] A = {1, 1};
  
      int n = A.length;
      int result = 0;
      for (int i = 0; i &lt; n - 1; i++) {
          if (A[i] == A[i + 1])
              result = result + 1;
      }
      int r = 0;
      for (int i = 0; i &lt; n; i++) {
          int count = 0;
          if (i &gt; 0) {
              if (A[i - 1] != A[i])
                  count = count + 1;
              else
                  count = count - 1;
          }
          if (i &lt; n - 1) {
              if (A[i + 1] != A[i])
                  count = count + 1;
              else
                  count = count - 1;
          }
          r = Math.max(r, count);
      }
      System.out.println(result + r);
  }
  </code></pre>
  
  <p>where I made mistake?</p>