Data Structures & AlgorithmsModerateTCS NQT · basics
Problem: What is the sum of the decimal digits of 2^15? Run the code.
Problem: What is the sum of the decimal digits of 2^15? Run the code.
print(sum(int(c) for c in str(2 ** 15)))What is printed?
- A. 25
- B. 26
- C. 22
- D. 5
Correct answer: B. 26
2¹⁵ = 32768, and 3 + 2 + 7 + 6 + 8 = 26. Using 2¹⁶ = 65536 gives 25, 2¹⁴ = 16384 gives 22, and 2⁵ = 32 gives 5.
More Coding Interview Problems questions
- Problem: How many integers in [1, 100] are not perfect squares? Run the code. python print(sum(1 for x in range(1, 101) if int(round(x…
- Problem: How many inversions does the array [5, 1, 4, 2, 3] have? Run the code. python a = [5, 1, 4, 2, 3] print(sum(1 for i in…
- Problem: What is the greatest common divisor of 12, 18, 30 and 42? Run the code. python from math import gcd from functools import reduce…
- Problem: What is the worst-case time complexity of binary search for the first occurrence of a value in a sorted array that contains…
- Problem: Which algorithm constructs an Euler circuit of a connected graph whose vertices all have even degree in linear time?
- Problem: What is the time complexity of computing the Z-array of a string of length n?