title: Tape-Equilibrium Codility Training program
body: <p>I submitted a solution to Tape Equilibrium problem in Codility. [Codility training][1]</p>
  
  <p>The problem is described as follows:</p>
  
  <blockquote>
    <p>A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape.
    Any integer P, such that 0 &lt; P &lt; N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1].
    The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|
    In other words, it is the absolute difference between the sum of the first part and the sum of the second part.</p>
  </blockquote>
  
  <p>The solution I submitted is:</p>
  
  <pre><code>class Solution {
    public int solution(int[] A) {
  
      long d = A[0] - A[A.length-1];
      int l = 1;
      int r = A.length -2;
  
      while(l &lt;= r) {
        if (Math.abs(d + A[l]) &lt; Math.abs(d - A[r])) {
          d += A[l];
          l++;
        }
        else {
          d -= A[r];
          r--;
        }
      }
      return (int) Math.abs(d);
    }
  }
  </code></pre>
  
  <p>I achieved 85% accuracy but couldn't get to correct for some use case. Can someone help me to find what's wrong with this solution. Thanks</p>