Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the sum of the digits of the number 2^64? Run the code.

Problem: What is the sum of the digits of the number 2^64? Run the code.
print(sum(int(c) for c in str(2 ** 64)))
What is printed?
  1. A. 87
  2. B. 88
  3. C. 20
  4. D. 65

Correct answer: B. 88

2⁶⁴ = 18446744073709551616, whose digits sum to 88. 2⁶⁴ − 1 (the uint64 maximum) gives 87, 20 is the number of digits, and 65 is the bit length.

More Coding Interview Problems questions

Exams that ask this topic