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?
  1. A. 13
  2. B. 14
  3. C. 11
  4. 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

Exams that ask this topic