I have the following problem:
You are given N counters, initially set to 0, and you have two possible operations on them:
with js max score that I can get is 77%
any improvement?
function solution(N, A) {
let counters = [];
//fill counter with 0
for (let i = 0; i < N; i += 1) {
counters[i] = 0;
}
//loop array and set counters
for (let i = 0; i < A.length; i += 1) {
//0 index fix
let position = A[i] - 1;
if (A[i] <= N) {
counters[position] += 1;
} else {
let max = Math.max(...counters);
counters.fill(max)
}
}
return counters;
}