1
function gcd(a, b) {
2
while (b > 0) {
3
a %= b;
4
[a, b] = [b, a];
5
}
6
return a;
7
}
8
function lcm(a, b) {
9
return (a / gcd(a, b)) * b;
10
}
11

12
var replaceNonCoprimes = function (nums) {
13
let res = new Array();
14
for (let num of nums) {
15
while (res.length > 0 && gcd(res.at(-1), num) > 1) {
16
num = lcm(res.at(-1), num);
17
res.pop();
18
}
19
res.push(num);
20
}
21
return res;
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0