Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

How many windows of size 3 in [1, 2, 2, 3, 4, 4, 5] have every pair of adjacent elements inside the window different?

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

Correct answer: A. 1

Maintain a count of equal adjacent pairs inside the window; a window is valid when that count is zero. Checking only the window's endpoints misses equal pairs in the middle.

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

Exams that ask this topic