GATE Computer ScienceHardGATE CS (PYQ pattern)
What is the length of the longest common subsequence of the three strings X = BDCABACDB, Y = ABCBDABDC and Z = BCADBDACB?
- A. 4
- B. 5
- C. 6
- D. 3
Correct answer: B. 5
Use the 3-dimensional table L[i][j][k] = L[i−1][j−1][k−1] + 1 when all three characters agree, else the maximum of the three one-step reductions; it ends with 5 (confirmed by running the DP). The LCS of any two strings is longer than the three-way LCS, so pairwise answers overestimate.
More Algorithms questions
- The longest repeating subsequence of a string is the longest subsequence that occurs twice, where the two copies may overlap in positions…
- 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…