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?

  1. A. 6
  2. B. 49
  3. C. 7
  4. 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

Exams that ask this topic