Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B

What is the length of the longest contiguous subarray of [4, 2, 4, 5, 6, 2, 4, 1] that contains no repeated value?

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

Correct answer: B. 5

Use a sliding window with the last-seen index of each value, moving the left end past the previous occurrence. The repeated 4 at the start forces the window to begin after index 0.

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

Exams that ask this topic