Data Structures & AlgorithmsHardGATE CS · ICPC regional
What is the length of the longest common subsequence of AGGTAB and GXTXAYB (letters need not be contiguous)?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
A subsequence common to both strings is GTAB. The DP over prefix pairs gives the length; using longest common substring gives a smaller value.
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 rank (1-based, in lexicographic order) of the string cab among all permutations of the letters a, b, c?
- How many trailing zeros does 2024! have in base 10?
- How many integers n with 2 <= n <= 200 are square-free (not divisible by the square of any integer greater than 1)?
- What is the sum of Euler's totient phi(i) for i = 1 to 10 (phi(i) counts the integers k in [1, i] with gcd(k, i) = 1)?
- How many integers x in [0, 20] satisfy x^3 ≡ x (mod 7)?
- The 3-row by 4-column matrix is filled row by row with 1 to 12. What is the 7th element when the matrix is read in clockwise spiral order…