Mid
From PDF
Coding
C# Coding Interview
Count Trailing Zeroes in Factorial of a Number?
Short answer: int TrailingZeroes(int n) { int count = 0; for (int i = 5; i <= n; i *= 5) { count += n / i; } return count; } Explanation: Trailing zeros come from factors of 10 = 2 × 5, but 2s are plenty, count 5s.
Example code
int TrailingZeroes(int n)
{
int count = 0;
for (int i = 5; i <= n; i *= 5)
{
count += n / i;
}
return count;
} Explanation: Trailing zeros come from factors of 10 = 2 × 5, but 2s are plenty, count 5s.
Real-world example (ShopNest)
In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png