Data Structures & AlgorithmsModerateTCS NQT · Infosys

For the values [2, 5, 3, 8, 1, 6], how many values give remainder 1 or 2 when divided by 3 (counted once for each value)?

  1. A. 4
  2. B. 1
  3. C. 3
  4. D. 6

Correct answer: A. 4

Compute x mod 3 for each value: 2, 2, 0, 2, 1, 0. Counting remainders 1 or 2 gives four values; the trap is counting only the remainder-1 class or the complementary set.

More Coding Interview Problems questions

Exams that ask this topic