Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers in [1, 100000] are multiples of 7 whose last digit is 3? Run the code.
Problem: How many integers in [1, 100000] are multiples of 7 whose last digit is 3? Run the code.
print(sum(1 for x in range(1, 100001) if x % 7 == 0 and x % 10 == 3))What is printed?
- A. 14285
- B. 1428
- C. 10000
- D. 1429
Correct answer: B. 1428
A multiple of 7 ends in 3 exactly when x ≡ 63 (mod 70), so the count is floor((100000 − 63)/70) + 1 = 1428. 14285 counts all multiples of 7, 10000 all numbers ending in 3, and rounding 100000/70 up gives 1429.
More Coding Interview Problems questions
- Problem: How many ordered pairs (x, y) with 1 <= x, y <= 12 satisfy x^2 + y^2 <= 100? Run the code. python print(sum(1 for x in range(1…
- Problem: How many lattice points (x, y) with x >= 0, y >= 0 and x + y <= 10 lie in the triangle? Run the code. python print(sum(1 for x in…
- Problem: What is the sum of the ASCII codes of the characters of 'hello'? Run the code. python print(sum(ord(c) for c in 'hello')) What is…
- Problem: What is the length of the longest strictly increasing contiguous subarray of [3, 4, 5, 1, 2, 3, 4, 5, 6]? Run the code. python a…
- Problem: What is the minimum number of cuts needed to partition 'abcde' into palindromes? Run the DP. python s = 'abcde' n = len(s) pal =…
- Problem: How many two-digit numbers have a digit sum that is a prime number? Run the code. python def isp(n): return n > 1 and all(n % d…