Data Structures & AlgorithmsHard

Counting subarrays whose sum is divisible by k with prefix remainders, which statement is TRUE?

  1. A. Only the last index of each remainder needs storing; first indices are never used.
  2. B. The count is unaffected by the seed if the array contains no zero elements.
  3. C. Seeding count[0] = 1 double-counts subarrays that start at index 0.
  4. D. The map must start with count[0] = 1, because the empty prefix has remainder 0 and pairs with any prefix of remainder 0.

Correct answer: D. The map must start with count[0] = 1, because the empty prefix has remainder 0 and pairs with any prefix of remainder 0.

The empty prefix at index 0 has remainder 0 and must be in the map, or every subarray beginning at the first element is lost. The other statements either misstate the first-index rule or claim a seed effect that depends on zeros, which is false.

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

Exams that ask this topic