TapeEquilibrium Codility JAVA solution (100/100)

This task can be easily done with prefix sums. In first for loop we create the sumArray which contains sum of all elements from A[1] to A[i]. After that, we iterate through sumArray. In position i, the element sumArray[i] tells us sum of elements from A[1] to A[i] and if we do sumArray[lastElement] – sumArray[i] we can get the sum of second half. Smallest difference between parts of array we get by absolute subtraction of sumArray[i] and sumArray[lastElement].