Created
June 16, 2018 14:10
-
-
Save adicuco/508b1576c92813f8c5d7ae23e2819795 to your computer and use it in GitHub Desktop.
100% solution for Max Counters Task on Codility
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(N, A) { | |
| var B = new Array(N); | |
| B.fill(0, 0, N); | |
| var max = 0; | |
| for (let i = 0; i < A.length; i++) { | |
| if (A[i] == N + 1) { | |
| if(A[i+1] == N+1){ | |
| continue; | |
| } else{ | |
| for(var j = 0; j< B.length;j++){ | |
| B[j]=max; | |
| }} | |
| } else { | |
| B[A[i] - 1]++; | |
| if (B[A[i] - 1] > max) max = B[A[i] - 1]; | |
| } | |
| } | |
| return B; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment