Data Structures & AlgorithmsModerateTCS NQT · CAT

Problem: What is gcd(462, 1071)?

  1. A. 147
  2. B. 21
  3. C. 7
  4. D. 3

Correct answer: B. 21

1071 = 2·462 + 147, 462 = 3·147 + 21, 147 = 7·21, so gcd = 21 (= 3 · 7). Stopping one step early gives 147, and 7 or 3 alone miss one of the two common primes.

More Coding Interview Problems questions

Exams that ask this topic