You are viewing a single comment's thread. Return to all comments →
Great,
We not only need to solve this puzzle but at the same time think of time complexity :).
We need to find numbers b/w two arrays, we can take max from a and min from b, then we can do calculation to find numbers.
This is what i'm doing in m beloved JS.
function getTotalX(a, b) { let total = 0; let maxA = Math.max(...a); let minB = Math.min(...b); let number = maxA;
let allElementsAreMultiple = false; let numberIsMultipleOfAll = false; while(number <= minB){ console.log('aMax ', maxA,'bMin ', minB, 'number ', number); // Every element of array must be a multiple of considerd number allElementsAreMultiple = a.every(ele => number%ele === 0 ); numberIsMultipleOfAll = b.every(ele => ele%number === 0 ); if( allElementsAreMultiple && numberIsMultipleOfAll ) total++; number++; } return total;
}
That makes it very easy for me.
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 →
Great,
We not only need to solve this puzzle but at the same time think of time complexity :).
We need to find numbers b/w two arrays, we can take max from a and min from b, then we can do calculation to find numbers.
This is what i'm doing in m beloved JS.
function getTotalX(a, b) { let total = 0; let maxA = Math.max(...a); let minB = Math.min(...b); let number = maxA;
}
That makes it very easy for me.