Mid/SeniorMath

Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

A trailing zero is produced by a factor of 10, which comes from pairing factors of 2 and 5 in the factorial product. Your solution should run in O(log n) time.

Example 1
Inputn = 3
Output0
Since 3! = 6, there are no trailing zeroes.
Example 2
Inputn = 5
Output1
Since 5! = 120, there is exactly one trailing zero.

Constraints

  • 0 <= n <= 10^4

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate