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)?
- A. 5
- B. 1
- C. 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the minimum number of letters you must insert (into either string) so that "leetcode" and "codeleet" become anagrams of each other?
- A string of 8 brackets is "]][[][][" where '[' and ']' appear equally often. Each operation swaps any two characters. What is the minimum…
- For each index i of [4, 2, 5, 3, 1, 6], let dist(i) be the distance to the next index j > i with a[j] < a[i] (dist = n − i if no such…
- Let A = [1, 4, 6, 9], B = [2, 3, 7] and S = [5, 9, 10, 13]. Count the ordered pairs (x from A, y from B) whose sum x + y lies in S.
- How many unordered pairs of positions in [5, 1, 4, 7, 2, 6] have bitwise XOR at most 3?
- What is the minimum number of characters you must DELETE from "aabbbccddddeee" so that every letter that remains appears the same number…