Data Structures & AlgorithmsHard

How many arrays of length 3 with entries in {0, 1, 2, 3} have a sum divisible by 4?

  1. A. 64
  2. B. 15
  3. C. 17
  4. D. 16

Correct answer: D. 16

Fix the first n−1 entries freely; the last entry is then forced to a unique residue, so there are m^(n−1) arrays. The total m^n counts all arrays, and the residue-1 count answers a different question.

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

Exams that ask this topic