Data Structures & AlgorithmsVery hardTCS NQT · Infosys

What is the length of the longest contiguous subarray of [1, 2, 1, 2, 3] that contains at most two distinct values?

  1. A. 4
  2. B. 5
  3. C. {C-1}
  4. D. 6

Correct answer: A. 4

The subarray 1, 2, 1, 2 has two distinct values and length 4; adding the 3 would make three distinct values.

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

Exams that ask this topic