Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: How many steps does Euclid's algorithm take on (2024, 748) before the remainder becomes 0?

Problem: How many steps does Euclid's algorithm take on (2024, 748) before the remainder becomes 0?
a, b = 2024, 748
steps = 0
while b:
    a, b = b, a % b
    steps += 1
print(steps)
What is printed?
  1. A. 6
  2. B. 4
  3. C. 5
  4. D. 7

Correct answer: C. 5

Each loop pass replaces the pair with (b, a mod b), and the count of passes is the number of steps.

More Coding Interview Problems questions

Exams that ask this topic