Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT

What is the length of the longest CONTIGUOUS block that appears in both arrays [1, 5, 3, 7, 2, 3, 7, 8] and [4, 7, 2, 3, 7, 9, 1] (equal values in the same order)?

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

Correct answer: C. 4

Use the DP dp[i][j] = dp[i−1][j−1] + 1 when a[i] = b[j], and track the maximum; the run must be contiguous, so a mismatch resets it to 0. The subsequence LCS allows gaps, so it can be longer.

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

Exams that ask this topic