logo

Back to questions

Factorial Trailing Zeroes [Microsoft Python Interview Question]

Medium

Before, you work on this question, make sure you've solved the easier warmup problem Factorial Formula, where you need to write a function to compute nn factorial as follows:

n!=n(n1)(n2).....21 n! = n * (n-1) * (n-2) * ..... 2 * 1.

Now that you know the factorial formula, let's write a function that returns the number of trailing zeroes in n!.

For example, for 5!5!, we'd return 1, because 5!=54321=1205! = 5 * 4 * 3 * 2 * 1 = 120 and 120 has exactly 1 trailing zero.

For 10!10!, which evaluates to 36288003628800 we'd return 2, becuase there are two trailing zeroes.

Python