You are viewing a single comment's thread. Return to all comments →

Here is smaller code bro,

def getTotalX(a, b): total = 0 for x in list(range(a[-1], b[0] + 1)): hold = 0 for v in a: if (x % v == 0): hold += 1 else: hold = 0; break for c in b: if (c % x == 0): hold += 1 else: hold = 0; break if (hold == len(a) + len(b)): total += 1 return total

Awesome bro

add a if condition above the 3rd for loop like:

if hold > 0:

for c in b: .... ....

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.

Thank you!

i don't get why we use this line? if (hold == len(a) + len(b)):

## Between Two Sets

You are viewing a single comment's thread. Return to all comments →

Here is smaller code bro,

Awesome bro

add a if condition above the 3rd for loop like:

if hold > 0:

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.

Thank you!

i don't get why we use this line? if (hold == len(a) + len(b)):