Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many windows of length 3 in [1, 2, 3, 1, 2, 2, 4, 1, 3, 4] contain three pairwise distinct values?

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

Correct answer: B. 6

There are 10 − 3 + 1 = 8 windows; slide a frequency map and test whether it holds 3 keys. Only [1,2,2] and [2,2,4] repeat a value, so 6 qualify. Counting every window gives 8, 10 is the array length, and 3 counts only the non-overlapping blocks.

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

Exams that ask this topic