Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many two-digit numbers have a digit sum that is a prime number? Run the code.
Problem: How many two-digit numbers have a digit sum that is a prime number? Run the code.
def isp(n):
return n > 1 and all(n % d for d in range(2, int(n ** 0.5) + 1))
print(sum(1 for x in range(10, 100) if isp(sum(map(int, str(x))))))What is printed?- A. 37
- B. 21
- C. 34
- D. 33
Correct answer: D. 33
Two-digit numbers with digit sum 2, 3, 5, 7, 11, 13 or 17 number 33. Including 1..9 adds 4 for 37, 21 counts two-digit primes, and treating digit sum 1 (the number 10) as prime gives 34.
More Coding Interview Problems questions
- Problem: How many subarrays of [1, 2, 2, 3, 3, 3] have all equal maximum and minimum values? Run the code. python a = [1, 2, 2, 3, 3, 3]…
- Problem: How many integers in [1, 100] have exactly two prime factors counted with multiplicity? Run the code. python def omega(n): c = 0…
- Problem: What is the sum of all proper divisors of 220 (divisors smaller than 220)? Run the code. python print(sum(d for d in range(1…
- Problem: What is the minimum number of coins from {1, 6, 10} that sum to 37? Run the DP. python INF = 10 9 d = [0] + [INF] 37 for v in…
- Problem: How many distinct arrangements of the letters of 'MISSISSIPPI' exist? Run the code. python import math print(math.factorial(11)…
- Problem: What is the maximum total of two non-overlapping subarrays of length 2 in [1, 5, 2, 8, 3]? Run the code. python a = [1, 5, 2, 8…