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.
def getTotalX(a, b):
# Write your code here
max_num = min(b) # as the number has to be a factor of all numbers in b, it can't be greater than any of the numbers in list b.
min_num = max(a) # as every number in list a is a factor the number should be greater than every number in list a.
result_set = set()
for i in range(min_num, max_num+1):
r_a = map(lambda x: i % x == 0, a)
if all(r_a):
r_b = map(lambda x: x % i == 0, b)
if all(r_b):
result_set.add(i)
return len(result_set)
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 →
def getTotalX(a, b): # Write your code here max_num = min(b) # as the number has to be a factor of all numbers in b, it can't be greater than any of the numbers in list b. min_num = max(a) # as every number in list a is a factor the number should be greater than every number in list a. result_set = set() for i in range(min_num, max_num+1): r_a = map(lambda x: i % x == 0, a) if all(r_a): r_b = map(lambda x: x % i == 0, b) if all(r_b): result_set.add(i) return len(result_set)