I have the following problem:
You are given N counters, initially set to 0, and you have two possible operations on them:
ES6
const solution = (n, a) => {
// Initialize to zero
let counter = new Array(n);
for(let i = 0 ; i < n ; i++ ){
counter[i] = 0;
}
let max = 0;
for(let j = 0 ; j < a.length ; j++ ){
const item = a[j];
if( item > n) {
for(let i = 0 ; i < n ; i++ ){
counter[i] = max;
}
}
else{
counter[item-1]++;
if(max < counter[item-1])
{
max = counter[item-1];
}
}
}
return counter;
};