Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: What is the number of trailing zeros in 2025! (in decimal)? Run the code.

Problem: What is the number of trailing zeros in 2025! (in decimal)? Run the code.
n = 2025
c = 0
p = 5
while p <= n:
    c += n // p
    p *= 5
print(c)
What is printed?
  1. A. 405
  2. B. 486
  3. C. 505
  4. D. 506

Correct answer: C. 505

Legendre: 405 + 81 + 16 + 3 = 505. Counting only multiples of 5 gives 405, stopping at 25 gives 486, and the rough n/4 estimate gives 506.

More Coding Interview Problems questions

Exams that ask this topic