Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: How many distinct values does the expression (i * j) mod 7 take as i and j range independently over 1 ≤ i, j ≤ 7?
- A. 6
- B. 49
- C. 7
- D. 28
Correct answer: C. 7
Because i and j can both be 7 ≡ 0, the product can be 0, and for i, j in 1..6 every non-zero residue appears (7 is prime), so all 7 values 0..6 occur. Forgetting the 0 gives 6, 49 counts ordered (i, j) pairs, and 28 counts unordered pairs instead of distinct values.
More Coding Interview Problems questions
- Problem: What does the following print? python x = [[0] 2] 2 x[0][1] = 5 print(x)
- Problem: What does the following print? python print(0.1 + 0.2 == 0.3, round(2.5), round(3.5))
- Problem: What does the following print? python a = [1, 2, 3] b = a b += [4] print(a)
- Problem: What does the following print? python print(int('0b101', 0), int('101', 2), 7 // 2 2)
- Problem: What does the following print? python fs = [lambda: i for i in range(3)] print([f() for f in fs])
- Problem: What does the following print? python print(len({1, 2, 3} & {2, 3, 4} | {5}))