Data Structures & AlgorithmsHardCAT · Codeforces Div2 B

What is the sum, over all contiguous windows of length 3, of the number of distinct values in the window, for the array [1, 2, 1, 3, 4, 2, 3]?

  1. A. 15
  2. B. 13
  3. C. 14
  4. D. 17

Correct answer: C. 14

Maintain counts of values in the window: a value contributes one distinct element only when its count goes from 0 to 1 on entry. Repeated values inside a window must not be counted twice.

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

Exams that ask this topic