Data Structures & AlgorithmsModerateTCS NQT · ICPC regional
Problem: How many trailing zeros does 30! have in base 10?
- A. 6
- B. 3
- C. 7
- D. 26
Correct answer: C. 7
Legendre: 30 // 5 + 30 // 25 = 6 + 1 = 7, because 25 contributes two 5s. Counting multiples of 5 only gives 6, 30 // 10 gives 3, and 26 counts factors of 2, which are never the bottleneck.
More Coding Interview Problems questions
- Problem: How many unordered pairs {x, y} with x ≠ y from the set {1, 2, 3, 4, 5} have x + y even?
- Problem: How many binary strings of length 4 contain no two adjacent 1s?
- Problem: How many two-digit numbers (10–99) have digits that sum to exactly 9?
- Problem: The undirected graph on vertices 0, 1, 2 has edges 0-1 (5), 1-2 (5) and 0-2 (12). What is the shortest path length from 0 to 2?
- Problem: A complete binary tree has all levels full with depths 0 to 4 (root at depth 0). How many nodes does it have in total?
- Compute the sum of gcd(i, j) over all pairs 1 ≤ i < j ≤ 50. python from math import gcd print(sum(gcd(i,j) for i in range(1,51) for j in…