LeetCode 172, Medium. Topics: Math. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 26 parametrized pytest cases, and a playground notebook:
Problem
Given an integer <code>n</code>, return <em>the number of trailing zeroes in </em><code>n!</code>.
<p>Note that <code>n! = n * (n - 1) * (n - 2) * … * 3 * 2 * 1</code>.</p>
Examples
Constraints
<p><strong>Follow up:</strong> Could you write a solution that works in logarithmic time complexity?</p>
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026