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.
Between Two Sets
Between Two Sets
Sort by
recency
|
3068 Discussions
|
Please Login in order to post a comment
This solution is best using the brute-force approach — it's shorter, faster, and cleaner vs LCM and GCD traditional.
I forgot math concepts and did this instead.
from math import gcd from functools import reduce
Function to compute LCM of two numbers
def lcm(x, y): return x * y // gcd(x, y)
Function to compute LCM of a list
def lcm_list(arr): return reduce(lcm, arr)
Function to compute GCD of a list
def gcd_list(arr): return reduce(gcd, arr)
def getTotalX(a, b): l = lcm_list(a) g = gcd_list(b)
The statement is very confusing. Fix it please.