GATE Computer ScienceHardGATE CS (PYQ pattern)
The longest repeating subsequence of a string is the longest subsequence that occurs twice, where the two copies may overlap in positions but the k-th characters of the two copies must come from different positions. What is its length for XYZXYZXY?
- A. 5
- B. 4
- C. 6
- D. 7
Correct answer: A. 5
Take the LCS DP of the string with itself, but forbid matching a character with itself (i ≠ j). The result is 5: XYZXY occurs at positions (0,1,2,3,4) and (3,4,5,6,7), and the pairs of positions are all different.
More Algorithms questions
- Characters may be added ONLY at the front of the string abacdcabxab. What is the minimum number of characters that must be added to make…
- A digit string is decoded using A = 1, B = 2, …, Z = 26, and each code must be a valid letter number (so 0 is allowed only as part of 10…
- What is the maximum product of a non-empty contiguous subarray of [−2, 3, −4, 0, 5, −1, 2, −3, −1, 4]?
- The numbers 19, 5, 9, 18, 10, 29, 5, 24, 10 are split into two groups (every number goes into exactly one group). What is the smallest…
- A + or − sign is placed in front of each of the numbers 1, 1, 2, 3, 5, 8, 13, 21 (the two 1s are different items). In how many ways is the…
- An unbounded knapsack has capacity 47 and item types (weight, value): (5, 11), (8, 19), (9, 20), (13, 29), each available any number of…