Data Structures & AlgorithmsModerateTCS NQT · number puzzle
Problem: How many decimal digits does 100! have? Run the code.
Problem: How many decimal digits does 100! have? Run the code.
import math print(len(str(math.factorial(100))))What is printed?
- A. 100
- B. 156
- C. 160
- D. 158
Correct answer: D. 158
100! is about 9.33 * 10^157, which has 158 digits. The estimate from Stirling's formula lands near the same value, which is the sanity check.
More Coding Interview Problems questions
- Problem: What is the digit sum of 100!? Run the code. python import math print(sum(int(c) for c in str(math.factorial(100)))) What is…
- Problem: Longest path in a weighted DAG from vertex 0 with edges 0->1 (3), 1->2 (4), 0->2 (10). Run the DP over the topological order…
- Problem: How many ordered sequences of jumps of sizes 2, 3 or 5 sum exactly to 12? Run the DP. python ways = [1] + [0] 12 for v in…
- Problem: What is the size of the largest divisible subset of [1, 2, 4, 8, 3] (every pair must satisfy one dividing the other)? Run the…
- Problem: How many subarrays of [1, 2, 1, 2, 3] contain exactly 2 distinct values? Run the code using the 'at most' trick. python from…
- Problem: Dijkstra from 0 with edges (0,1,1), (1,3,2), (0,2,4), (2,3,1). Which vertex sequence is the shortest path from 0 to 3? Run the…