Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: What is the sum of the digits of 3^20? Run the code.
Problem: What is the sum of the digits of 3^20? Run the code.
print(sum(int(c) for c in str(3 ** 20)))What is printed?
- A. 36
- B. 45
- C. 27
- D. 10
Correct answer: B. 45
3²⁰ = 3486784401, whose digits sum to 45. 3¹⁹ gives 36, 3²¹ gives 27, and 10 is the number of digits.
More Coding Interview Problems questions
- Problem: How many paths of length 3 exist in a complete graph K4 that start and end at different vertices? Run the code (count ordered…
- Problem: What is the number of integers in [1, 1000] whose digits are all odd? Run the code. python print(sum(1 for x in range(1, 1001) if…
- Problem: What is the length of the longest subarray of [5, 1, 4, 2, 3, 6] whose elements can be sorted to form consecutive integers? Run…
- Problem: How many integers from 1 to 1000 are not divisible by any of 2, 3, 5 and 7? Run the code. python print(sum(1 for x in range(1…
- Problem: What is the maximum sum of a subsequence (not necessarily contiguous) of [4, -2, 5, -1, 3] with no two chosen elements adjacent?…
- Problem: How many ways are there to write 12 as a sum of distinct positive integers (partitions into distinct parts)? Run the DP. python…