Data Structures & AlgorithmsModerate

How many contiguous windows of length 3 in 1 2 3 1 2 2 4 5 consist of three DIFFERENT values?

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

Correct answer: C. 4

A window of length 3 has three different values exactly when no two of its three entries coincide, so check all three pairs or the set size. Looking only at the outer entries or at adjacent pairs gives a different count.

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

Exams that ask this topic