Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT

What is the length of the longest contiguous block of [1, 2, 3, 1, 2, 3, 4, 2, 3, 4] that appears at least twice in the array WITHOUT overlapping the other copy?

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

Correct answer: C. 3

Try each length L and each pair of start positions (i, j) with j ≥ i + L, comparing the two blocks; the largest matching L is the answer. Allowing the two copies to overlap gives a longer block that is not valid.

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

Exams that ask this topic