FastPrepFactorial Trailing Zeroes

Factorial Trailing Zeroes

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Given a nonnegative integer n, return the number of trailing zeroes in the decimal representation of n!.

Function

trailingZeroes(n: int) → int

Examples

Example 1

n = 5return = 1

5! = 120, which ends with one zero.

Example 2

n = 30return = 7

The factors 5, 10, 15, 20, 25, and 30 contribute six factors of five, and 25 contributes one additional factor.

Constraints

  • 0 <= n <= 10^9
  • 0! = 1

More Microsoft problems

See Microsoft hiring insights
public int trailingZeroes(int n) {
  // Write your code here.
}
n5
expected1
Checking account…