← Back to challenges

Factorial Trailing Zeroes

JavaScriptHardmathnumbers

Instructions

Create a function that, given a positive integer n, returns the number of trailing zeroes in n!.

Examples

trailingZeroes(6) ➞ 1
// factorial(6) = 720

trailingZeroes(30) ➞ 7
// factorial(30) = 265252859812191058636308480000000

Notes

  • Create a solution that works in logarithmic time complexity.
  • n! = n * (n-1) * (n-2) * ... * 2 * 1
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.