Data Structures & AlgorithmsHard

How many NON-EMPTY prefixes of 3 2 5 1 4 5 2 (the first k elements, k ≥ 1) have a sum divisible by 5?

  1. A. 0
  2. B. 5
  3. C. 4
  4. D. 2

Correct answer: C. 4

A prefix is determined by its end index, so test the running sum at each step. Suffixes, an off-by-one that includes the empty prefix, or single elements divisible by 5 each count something else.

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

Exams that ask this topic