Data Structures & AlgorithmsModerateTCS NQT · CAT
Problem: What is gcd(462, 1071)?
- A. 147
- B. 21
- C. 7
- 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
- Problem: What is the determinant of the matrix [[2, 1], [1, 3]]?
- Problem: How many permutations of the letters A, B, C, D leave no letter in its original position (for example, A is not in the first…
- Problem: The sum of all integers from 1 to 200 that are divisible by neither 4 nor 7 is what value?
- Problem: How many integers from 1 to 100 inclusive are divisible by 7 but not by 14?
- Problem: What is the least common multiple of 6, 8 and 12?
- Problem: How many trailing zeros does 30! have in base 10?