Skip to content

Instantly share code, notes, and snippets.

@esperancaJS
Created August 7, 2016 22:31
Show Gist options
  • Save esperancaJS/ec818ea9fa82e717a5897fe1cc9c8d15 to your computer and use it in GitHub Desktop.
Save esperancaJS/ec818ea9fa82e717a5897fe1cc9c8d15 to your computer and use it in GitHub Desktop.
NumberSolitaire Javascript Codility 100%
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
var d = 6;
var n = A.length;
maxScore = [];
//for 0
for (var i = 0; i < d; i++){
maxScore.push(A[0]);
}
//for >0
for (var i = 1; i<n; i++){
maxScore[i % d] = Math.max.apply(Math, maxScore) + A[i];
//console.log(maxScore, i, i%d);
}
return maxScore[(n - 1) % d];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment