Created
          August 7, 2016 22:31 
        
      - 
      
- 
        Save esperancaJS/ec818ea9fa82e717a5897fe1cc9c8d15 to your computer and use it in GitHub Desktop. 
    NumberSolitaire Javascript Codility 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
    
  
  
    
  | // 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