easy +5 pts

Count trailing zeros

Compute how many zeros are at the end of a positive integer's decimal representation.

Write a function `count_trailing_zeros(n)` that takes a positive integer `n` and returns the number of consecutive zeros at the end of its decimal representation. For example, the number 1200 has two trailing zeros because its decimal representation ends with '00'. The number 7 has zero trailing zeros because it does not end with zero. Your implementation must not convert the integer to a string. Work with arithmetic operations only. **Function signature:** ```python def count_trailing_zeros(n: int) -> int: ... ``` **Input:** A positive integer `n` (1 ≤ n ≤ 10^9). **Output:** An integer, the count of trailing zeros.

Constraints

1 ≤ n ≤ 10^9. The function should be efficient; O(number of trailing zeros) is acceptable.

Example

```python
>>> count_trailing_zeros(1200)
2
>>> count_trailing_zeros(7)
0
>>> count_trailing_zeros(0)
1  # Note: 0 has one digit '0' at its end
```
5 points ~5 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Think about what operation removes the last digit from an integer.
The number 10 has one trailing zero. How can you check if a number ends with zero without using strings?
Use a while loop that keeps dividing by 10 and counting until the number is no longer divisible by 10.
Remember to handle the special case where n == 0.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.