Skip to main content
2 of 2
added 42 characters in body
Alex A.
  • 24.7k
  • 5
  • 38
  • 119

Julia, 34 31 30 bytes

n->find(digits(prod(1:n)))[]-1

This is an anonymous function that accepts any signed integer type and returns an integer. To call it, assign it to a variable. The larger test cases require passing n as a larger type, such as a BigInt.

We compute the factorial of n (manually using prod is shorter than the built-in factorial), get an array of its digits in reverse order, find the indices of the nonzero elements, get the first such index, and subtract 1.

Try it online! (includes all but the last test case because the last takes too long)

Saved a byte thanks to Dennis!

Alex A.
  • 24.7k
  • 5
  • 38
  • 119