Skip to content
Decoder

Factorial Trailing Zeroes

Medium

Problem

Return how many trailing zeros n! has (n! = n · (n - 1) · ... · 2 · 1). Can you do it in logarithmic time, without computing the factorial?

Example 1

Input
n = 3
Output
0
Why
3! = 6

Example 2

Input
n = 5
Output
1
Why
5! = 120

Example 3

Input
n = 25
Output
6

Constraints

  • 0 <= n <= 10^4

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.