Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: What is the number of trailing zeros in 30!? Run the code.
Problem: What is the number of trailing zeros in 30!? Run the code.
n = 30
c = 0
p = 5
while p <= n:
c += n // p
p *= 5
print(c)What is printed?- A. 7
- B. 6
- C. 3
- D. 26
Correct answer: A. 7
Zeros come from factors of 5: 30 // 5 + 30 // 25 = 6 + 1 = 7, with 25 giving an extra 5. Stopping at multiples of 5 gives 6, 30 // 10 gives 3, and 26 counts factors of 2, which are not the scarce ones.
More Coding Interview Problems questions
- Problem: How many integers in [1, 500] are perfect squares or multiples of 7? Run the code. python print(sum(1 for x in range(1, 501) if…
- Problem: What is the minimum number of operations to make all elements of [4, 7, 1] equal to their minimum by decrementing? Run the code…
- Problem: What is the number of paths from (1,1) to (3,3) moving only right or up in a grid with all cells free? Run the DP. python g =…
- Problem: How many distinct values does a XOR b take for a, b in {0, 1, 2, 3}? Run the code. python print(len({a ^ b for a in range(4) for…
- Problem: What is the sum of all integers in [1, 200] that are both odd and multiples of 5? Run the code. python print(sum(x for x in…
- Problem: What is the maximum number of distinct characters in a substring of length 4 of 'abcabcabc'? Run the code. python s = 'abcabcabc'…