Skip to content

Instantly share code, notes, and snippets.

@adicuco
Created June 16, 2018 14:10
Show Gist options
  • Select an option

  • Save adicuco/508b1576c92813f8c5d7ae23e2819795 to your computer and use it in GitHub Desktop.

Select an option

Save adicuco/508b1576c92813f8c5d7ae23e2819795 to your computer and use it in GitHub Desktop.
100% solution for Max Counters Task on Codility
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