Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many pairs (i, j) with 1 <= i < j <= 20 satisfy i j ≡ 1 (mod 7)? Run the code.
Problem: How many pairs (i, j) with 1 <= i < j <= 20 satisfy i * j ≡ 1 (mod 7)? Run the code.
print(sum(1 for i in range(1, 21) for j in range(i + 1, 21) if (i * j) % 7 == 1))What is printed?
- A. 24
- B. 48
- C. 30
- D. 2
Correct answer: A. 24
Inverse pairs mod 7 are (1,1), (2,4), (3,5), (6,6); counting i < j across 1..20 gives 24. Ordered pairs give 48, allowing i = j gives 30, and 2 counts only pairs inside 1..7.
More Coding Interview Problems questions
- Problem: What is the smallest n such that n! exceeds 10^10? Run the code. python import math n = 1 while math.factorial(n) <= 10 10: n +=…
- Problem: What is the sum of the lengths of all subarrays of an array of length 6? Run the code. python n = 6 print(sum(i (n - i + 1) for i…
- Problem: What is the longest run of consecutive 1 bits in the binary representation of 1000? Run the code. python x = 1000 best = cur = 0…
- Problem: How many ways are there to make 15 from unlimited coins of value 1, 5 and 10 (order does not matter)? Run the DP. python ways =…
- Problem: How many integers in [1, 100000] are multiples of 7 whose last digit is 3? Run the code. python print(sum(1 for x in range(1…
- 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…