Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: What is the number of integers x in [1, 200] for which x^2 + 2x + 1 is divisible by 7? Run the code.
Problem: What is the number of integers x in [1, 200] for which x^2 + 2x + 1 is divisible by 7? Run the code.
print(sum(1 for x in range(1, 201) if (x * x + 2 * x + 1) % 7 == 0))What is printed?
- A. 56
- B. 0
- C. 28
- D. 4
Correct answer: C. 28
(x + 1)² ≡ 0 (mod 7) iff 7 | x + 1 because 7 is prime, so x = 6, 13, …, 195: 28 values. Expecting two roots per period gives 56, testing x² + 1 gives 0, and wrongly requiring 49 | x + 1 gives 4.
More Coding Interview Problems questions
- Problem: How many integer solutions (x, y) satisfy x^2 + y^2 = 65 with x, y >= 0? Run the code. python print(sum(1 for x in range(0, 9)…
- Problem: What is the maximum length of a strictly decreasing subsequence of [9, 4, 6, 3, 8, 1] ? Run the code. python a = [9, 4, 6, 3, 8…
- Problem: How many numbers in [1, 1000] are divisible by 3 and whose digit sum is also divisible by 3? Run the code. python print(sum(1 for…
- Problem: What is the time complexity of finding all prime factors of n up to 10^12 by trial division?
- Problem: Which problem is solved by the 'meet in the middle' technique on a subset-sum instance with n = 40?
- Problem: What does the 'two-phase' Kosaraju algorithm compute?