Data Structures & AlgorithmsVery hard

What is the smallest positive integer k such that the residues of 3 5 8 12 14 modulo k (that is, each A[i] mod k) are all DISTINCT?

  1. A. 5
  2. B. 8
  3. C. 15
  4. D. 9

Correct answer: B. 8

Distinct residues need at least as many residues as elements, so k ≥ n is necessary, and checking k upward from n finds the first working modulus. Choosing n or the maximum plus one ignores whether the residues collide.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic