Skip to content

Instantly share code, notes, and snippets.

@yosoul93
Created July 11, 2018 18:05
Show Gist options
  • Save yosoul93/c93749c495fd98b7caffc3368fe033c4 to your computer and use it in GitHub Desktop.
Save yosoul93/c93749c495fd98b7caffc3368fe033c4 to your computer and use it in GitHub Desktop.
Count Non Divisor, it took me 35 minutes to solve it and this task is medium
function solution(A) {
var len = A.length,
count = [],
i,
k,
divisors = [],
result = [];
for (i = 0; i < 2 * len + 1; ++i){
count.push(0);
divisors.push(0);
}
for (i = 0; i < len; ++i){
++count[A[i]];
}
i = 1;
while (i <= 2 * len){
k = i;
while (k <= 2 * len){
divisors[k] += count[i];
k += i;
}
++i;
}
for (i = 0; i < len; ++i){
result.push(0);
result[i] = len - divisors[A[i]];
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment