Data Structures & AlgorithmsVery hardTCS NQT · Infosys

How many contiguous subarrays of length 3 in the array [1, 2, 3, 1, 2, 3, 3] have all three elements distinct?

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

Correct answer: B. 4

Check each window of length 3 for distinct values. Windows of equal values at the end are excluded, so only the first few windows qualify.

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

Exams that ask this topic