Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: What is the smallest n such that n! exceeds 10^10? Run the code.
Problem: What is the smallest n such that n! exceeds 10^10? Run the code.
import math
n = 1
while math.factorial(n) <= 10 ** 10:
n += 1
print(n)What is printed?- A. 13
- B. 14
- C. 11
- D. 10
Correct answer: B. 14
13! = 6227020800 ≤ 10¹⁰ but 14! = 87178291200 > 10¹⁰, so n = 14. Returning the last n that does not exceed gives 13, 11 is the digit count of 10¹⁰, and 10 wrongly assumes n! ≈ 10ⁿ.
More Coding Interview Problems questions
- Problem: What is the sum of the lengths of all subarrays of an array of length 6? Run the code. python n = 6 print(sum(i (n - i + 1) for i…
- Problem: What is the longest run of consecutive 1 bits in the binary representation of 1000? Run the code. python x = 1000 best = cur = 0…
- Problem: How many ways are there to make 15 from unlimited coins of value 1, 5 and 10 (order does not matter)? Run the DP. python ways =…
- Problem: How many integers in [1, 100000] are multiples of 7 whose last digit is 3? Run the code. python print(sum(1 for x in range(1…
- Problem: How many ordered pairs (x, y) with 1 <= x, y <= 12 satisfy x^2 + y^2 <= 100? Run the code. python print(sum(1 for x in range(1…
- Problem: How many lattice points (x, y) with x >= 0, y >= 0 and x + y <= 10 lie in the triangle? Run the code. python print(sum(1 for x in…