Data Structures & AlgorithmsVery hard

How many contiguous windows of length exactly 4 in 2 5 1 4 7 3 6 2 9 have DISTINCT elements AND a sum divisible by 3?

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

Correct answer: A. 3

Both conditions are checked per window: distinctness uses a set and the sum test uses the residue. Dropping either condition, or changing the window length to three, answers a different question.

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

Exams that ask this topic