Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the number of trailing zeros of 25 40 125? Run the code.

Problem: What is the number of trailing zeros of 25 * 40 * 125? Run the code.
n = 25 * 40 * 125
c = 0
while n % 10 == 0:
    n //= 10
    c += 1
print(c)
What is printed?
  1. A. 3
  2. B. 4
  3. C. 2
  4. D. 5

Correct answer: A. 3

Count paired 2s and 5s: 25 · 40 · 125 = 5² · (2³ · 5) · 5³ = 2³ · 5⁶, so only three 10s form and the product 125000 ends in 3 zeros. Counting the six 5s gives 6, but each zero also needs a 2.

More Coding Interview Problems questions

Exams that ask this topic