Factorial Trailing Zeroes

Published by persolut in

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
Watch a quick demo on how Edabit works.