Last active
August 20, 2016 17:03
-
-
Save esperancaJS/4729f87b24905b2fc6f7860b8b88f06e to your computer and use it in GitHub Desktop.
TieRopes Codility Javascript 100%
This file contains hidden or 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(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