Created
June 15, 2018 17:34
-
-
Save adicuco/0e5a6958aaaa21a87511b2f909ccfb5b to your computer and use it in GitHub Desktop.
100% solution for Tape Equilibrium Task on Codility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(A) { | |
var min = 99999999999; | |
var total = 0; | |
for (var i = 0; i < A.length; i++) { | |
total += A[i]; | |
} | |
var sum = 0; | |
for (var j = 0; j < A.length - 1; j++) { | |
sum += A[j]; | |
var res = Math.abs(sum - (total - sum)); | |
if (res < min) min = res; | |
} | |
return min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment