All problems
GCD of Array
Problem
Return the greatest common divisor of all integers in nums.
Fold the Euclidean algorithm across the list, starting the accumulator at 0 because gcd(0, x) is x. Return 0 for an empty list or a list containing only zeros.
Hint
gcd(a, b, c) equals gcd(gcd(a, b), c), so one running accumulator is enough.
Test cases
case 1
in: [[12,18,24]]
expected: 6
case 2
in: [[7]]
expected: 7
case 3
in: [[]]
expected: 0
case 4
in: [[0,0]]
expected: 0
case 5
in: [[5,10,15,20]]
expected: 5
Starter codePython
def gcd_array(nums):
# Your code here
pass5 test cases · run your code against them in the editor