Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers in [1, 10000] have a digit sum that is divisible by 7? Run the code.
Problem: How many integers in [1, 10000] have a digit sum that is divisible by 7? Run the code.
print(sum(1 for x in range(1, 10001) if sum(map(int, str(x))) % 7 == 0))What is printed?
- A. 1428
- B. 120
- C. 1421
- D. 139
Correct answer: C. 1421
Digit sums 7, 14, 21, 28, 35 in 1..10000 give 1421 numbers. 1428 counts multiples of 7 (digit sum ≠ value mod 7), digit sum exactly 7 gives 120, and stopping at 1000 gives 139.
More Coding Interview Problems questions
- Problem: How many integer solutions (a, b) with 1 <= a <= b <= 20 satisfy a b = 36? Run the code. python print(sum(1 for a in range(1, 21)…
- Problem: What is the length of the longest common subsequence of 'abcdef' and 'acebdf'? Run the DP. python a, b = 'abcdef', 'acebdf' dp =…
- Problem: What is the number of subsets of {1, 2, ..., 8} whose elements sum to a multiple of 8? Run the code. python print(sum(1 for m in…
- Problem: How many pairs (i < j) of [1, 4, 9, 16, 25] have a[j] - a[i] divisible by 3? Run the code. python a = [1, 4, 9, 16, 25]…
- Problem: What is the number of set bits in 2^30 - 1? Run the code. python print(bin(2 30 - 1).count('1')) What is printed?
- Problem: How many integers in [1, 300] are multiples of 6 but not of 9? Run the code. python print(sum(1 for x in range(1, 301) if x % 6…