All problems
LCM of Array
Problem
Return the least common multiple of all integers in nums.
Fold lcm(a, b) = a // gcd(a, b) * b across the list, dividing before multiplying to keep the numbers small. Return 0 if the list is empty or contains a zero.
Hint
Divide by the GCD before multiplying so the product never exceeds the true LCM.
Test cases
case 1
in: [[4,6]]
expected: 12
case 2
in: [[3,5,7]]
expected: 105
case 3
in: [[1]]
expected: 1
case 4
in: [[]]
expected: 0
case 5
in: [[0,5]]
expected: 0
Starter codePython
def lcm_array(nums):
# Your code here
pass5 test cases · run your code against them in the editor