ORIGINAL CODING QUESTION
Trailing factorial zeros
Return the number of trailing decimal zeros in x!, with 0!=1. Do not construct the factorial.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
One nonnegative integer x.
Constraints
0 ≤ x ≤ 1000000.
Example 1
Input
25
Output
6
Multiples of 5 contribute five factors; 25 contributes one extra.
Example 2
Input
4
Output
0
No factor of five appears.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
A trailing zero requires a factor of ten.
Hint 2
Factors of five are scarcer than factors of two.
Hint 3
Count multiples of 5,25,125 and so on.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →