Data Structures & AlgorithmsHard

For each contiguous window of length 3 in [1, 2, 1, 3, 2, 1], count the number of distinct values inside it, then add these counts over all windows. What is the total?

  1. A. 22
  2. B. 11
  3. C. 4
  4. D. 12

Correct answer: B. 11

For each window of length 3 the number of distinct values is the size of its set, and the total is the sum of these per-window counts. Adding the window sums, counting windows, or summing the maxima each measure something else.

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

Exams that ask this topic