Skip to content

Instantly share code, notes, and snippets.

@balazsnemeth
Last active March 25, 2021 06:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balazsnemeth/352e3230a0868ea811817e919a044f07 to your computer and use it in GitHub Desktop.
Save balazsnemeth/352e3230a0868ea811817e919a044f07 to your computer and use it in GitHub Desktop.
Solution for Count Non Divisible
// Solution for CountNonDivisible (Codility)
// Not the best, just O(N^2)...
// https://codility.com/programmers/lessons/11-sieve_of_eratosthenes/count_non_divisible/
function solution(A) {
// write your code in JavaScript (Node.js 6.4.0)
const divisors = A.map(e => 0);
for (let i = 0; i<A.length; i++) {
let e = A[i];
for (let j = i+1; j<A.length; j++) {
let f = A[j];
if (f % e === 0) {
divisors[j]++;
}
if (e % f === 0) {
divisors[i]++;
}
}
}
const res = divisors.map(e => A.length - e - 1);
// console.log("res: ", res);
return res;
}
@mustafaberat
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment