We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My favorite solution although it might take awhile to compile with different constraints.
I wonder if there's a way to "clean up" my solution, which uses the lengths of both arrays as constraints.
function getTotalX(a, b) {
let maxIntA = Math.max(...a);
let minIntB = Math.min(...b);
let intsBetweenArrays = [];
let newArrA = [];
let finalArr = [];
// let isDivisible = Boolean;
if (maxIntA > minIntB) {
return 0;
} else {
for (let i = maxIntA; i <= minIntB; i++) {
intsBetweenArrays.push(i);
}
for (let i = 0; i < intsBetweenArrays.length; i++) {
if (a.every(num => intsBetweenArrays[i] % num === 0)) {
newArrA.push(intsBetweenArrays[i]);
}
}
for (let i = 0; i < newArrA.length; i++) {
if (b.every(num => num % newArrA[i] === 0)) {
finalArr.push(newArrA[i]);
}
}
}
return finalArr.length;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
My favorite solution although it might take awhile to compile with different constraints.
I wonder if there's a way to "clean up" my solution, which uses the lengths of both arrays as constraints.
function getTotalX(a, b) {
}