Data Structures & AlgorithmsModerateTCS NQT · number theory

Problem: What is the greatest common divisor of 12, 18, 30 and 42? Run the code.

Problem: What is the greatest common divisor of 12, 18, 30 and 42? Run the code.
from math import gcd
from functools import reduce
print(reduce(gcd, [12, 18, 30, 42]))
What is printed?
  1. A. 6
  2. B. 2
  3. C. 3
  4. D. 12

Correct answer: A. 6

Each value is divisible by 6 and no larger number divides all four, so the gcd is 6.

More Coding Interview Problems questions

Exams that ask this topic