Tasks Details
medium
Calculate the number of elements of an array that are not divisors of each element.
Task Score
100%
Correctness
100%
Performance
100%
You are given an array A consisting of N integers.
For each number A[i] such that 0 ≤ i < N, we want to count the number of elements of the array that are not the divisors of A[i]. We say that these elements are non-divisors.
For example, consider integer N = 5 and array A such that:
A[0] = 3 A[1] = 1 A[2] = 2 A[3] = 3 A[4] = 6For the following elements:
- A[0] = 3, the non-divisors are: 2, 6,
- A[1] = 1, the non-divisors are: 3, 2, 3, 6,
- A[2] = 2, the non-divisors are: 3, 3, 6,
- A[3] = 3, the non-divisors are: 2, 6,
- A[4] = 6, there aren't any non-divisors.
Write a function:
function solution(A);
that, given an array A consisting of N integers, returns a sequence of integers representing the amount of non-divisors.
Result array should be returned as an array of integers.
For example, given:
A[0] = 3 A[1] = 1 A[2] = 2 A[3] = 3 A[4] = 6the function should return [2, 4, 3, 2, 0], as explained above.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..50,000];
- each element of array A is an integer within the range [1..2 * N].
Copyright 2009–2025 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used JavaScript
Time spent on task 15 minutes
Notes
not defined yet
Code: 09:18:19 UTC,
java,
autosave
Code: 09:21:43 UTC,
js,
autosave
Code: 09:23:13 UTC,
js,
autosave
Code: 09:23:32 UTC,
js,
autosave
Code: 09:23:53 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[A[i]] = true
}
}
Code: 09:24:07 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count
}
}
Code: 09:24:17 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
}
Code: 09:25:01 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
}
Code: 09:25:14 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
}
}
Code: 09:25:36 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
}
}
Code: 09:25:49 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
}
Code: 09:26:06 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; i < A.length; i++) {
}
}
}
Code: 09:26:20 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] < A.length; i++) {
}
}
}
Code: 09:26:30 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
}
}
}
Code: 09:26:42 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if()
}
}
}
Code: 09:27:12 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divs[A[i] * k]) {
count[A[i] * k]
}
}
}
}
Code: 09:27:40 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divs[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
}
}
Code: 09:28:11 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divs[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
annswer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:28:14 UTC,
js,
verify,
result: Failed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divs[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
annswer.push(A.length - count[A[i]]);
}
return answer;
}
Analysis
expand all
Example tests
1.
0.072 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
ReferenceError: divs is not defined at solution (solution.js:22:13) at solutionWrapper (/tmp/exec.js:409:28) at Promise.resolve.then (/tmp/exec.js:435:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
Code: 09:28:24 UTC,
js,
verify,
result: Failed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
annswer.push(A.length - count[A[i]]);
}
return answer;
}
Analysis
expand all
Example tests
1.
0.072 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
ReferenceError: annswer is not defined at solution (solution.js:30:9) at solutionWrapper (/tmp/exec.js:409:28) at Promise.resolve.then (/tmp/exec.js:435:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
Code: 09:28:32 UTC,
js,
verify,
result: Passed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Analysis
Code: 09:28:48 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:29:08 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:29:18 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:29:48 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:29:58 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:30:17 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
// checking if product of A[i]
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:30:38 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let i = 0; i < A.length; i++) {
for (let k = 2; k * A[i] <= max; k++) {
// checking for products of A[i] exist in A and counting them
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:31:00 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of ) {
for (let k = 2; k * A[i] <= max; k++) {
// checking for products of A[i] exist in A and counting them
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:31:11 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of A[i] exist in A and counting them
if (divisible[A[i] * k]) {
count[A[i] * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:31:23 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let i = 0; i < A.length; i++) {
answer.push(A.length - count[A[i]]);
}
return answer;
}
Code: 09:31:54 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
Code: 09:31:56 UTC,
js,
verify,
result: Passed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
Analysis
Code: 09:32:24 UTC,
js,
autosave
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
Code: 09:32:46 UTC,
js,
verify,
result: Passed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
User test case 1:
[1]
User test case 2:
[1, 1, 1, 1, 1, 1, 1, 1]
User test case 3:
[1, 1, 1, 1, 1, 1, 2, 1]
User test case 4:
[1, 2, 1, 2]
User test case 5:
[50000, 50000, 1, 2, 5, 50, 100]
Analysis
expand all
User tests
1.
0.072 s
OK
function result: [0]
function result: [0]
1.
0.072 s
OK
function result: [0, 0, 0, 0, 0, 0, 0, 0]
function result: [0, 0, 0, 0, 0, 0, 0, 0]
1.
0.072 s
OK
function result: [1, 1, 1, 1, 1, 1, 0, 1]
function result: [1, 1, 1, 1, 1, 1, 0, 1]
1.
0.072 s
OK
function result: [2, 0, 2, 0]
function result: [2, 0, 2, 0]
1.
0.084 s
OK
function result: [0, 0, 6, 5, 5, 3, 2]
function result: [0, 0, 6, 5, 5, 3, 2]
Code: 09:33:05 UTC,
js,
verify,
result: Passed
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
User test case 1:
[1]
User test case 2:
[1, 1, 1, 1, 1, 1, 1, 1]
User test case 3:
[1, 1, 1, 1, 1, 1, 2, 1]
User test case 4:
[1, 2, 1, 2]
User test case 5:
[50000, 50000, 1, 2, 5, 50, 100]
Analysis
expand all
User tests
1.
0.072 s
OK
function result: [0]
function result: [0]
1.
0.072 s
OK
function result: [0, 0, 0, 0, 0, 0, 0, 0]
function result: [0, 0, 0, 0, 0, 0, 0, 0]
1.
0.072 s
OK
function result: [1, 1, 1, 1, 1, 1, 0, 1]
function result: [1, 1, 1, 1, 1, 1, 0, 1]
1.
0.072 s
OK
function result: [2, 0, 2, 0]
function result: [2, 0, 2, 0]
1.
0.084 s
OK
function result: [0, 0, 6, 5, 5, 3, 2]
function result: [0, 0, 6, 5, 5, 3, 2]
Code: 09:33:08 UTC,
js,
final,
score: 
100
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const max = Math.max(...A);
let divisible = [];
let count = [];
// set divisible and count to default value up to max
for (let i = 0; i <= max; i++) {
divisible[i] = false;
count[i] = 0;
}
// marking if value exists and counting how many times
for (let i = 0; i < A.length; i++) {
divisible[A[i]] = true;
count[A[i]]++;
}
for (let val of A) {
for (let k = 2; k * val <= max; k++) {
// checking for products of val exist in A and counting them
if (divisible[val * k]) {
count[val * k]++;
}
}
}
let answer = [];
for (let val of A) {
answer.push(A.length - count[val]);
}
return answer;
}
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(N * log(N))
expand all
Correctness tests
1.
0.072 s
OK
2.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
3.
0.072 s
OK
1.
0.072 s
OK
1.
0.072 s
OK
1.
0.072 s
OK
2.
0.072 s
OK
expand all
Performance tests
1.
0.092 s
OK
2.
0.084 s
OK
1.
0.120 s
OK
2.
0.380 s
OK
1.
0.140 s
OK
2.
0.128 s
OK
1.
0.164 s
OK
2.
0.120 s
OK
3.
0.136 s
OK