Skip to content

Instantly share code, notes, and snippets.

@esperancaJS
Last active August 20, 2016 17:03
Show Gist options
  • Save esperancaJS/4729f87b24905b2fc6f7860b8b88f06e to your computer and use it in GitHub Desktop.
Save esperancaJS/4729f87b24905b2fc6f7860b8b88f06e to your computer and use it in GitHub Desktop.
TieRopes Codility Javascript 100%
function solution(K, A) {
var possibleRopesCount = 0;
var fromPrev = 0;
for (var i = 0; i<A.length; i++){
if((fromPrev + A[i]) >= K){
possibleRopesCount++;
fromPrev = 0;
} else {
fromPrev = fromPrev + A[i];
}
}
return possibleRopesCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment