Data Structures & AlgorithmsModerateGATE CS · TCS NQT
What is the length of the longest common subsequence of the strings "AGGTABQZ" and "GXTXAYBZQ"?
- A. 1
- B. 6
- C. 5
- D. 7
Correct answer: C. 5
A longest common subsequence keeps letters that are not contiguous in either string, so it is generally longer than the longest common SUBSTRING. The DP takes the max of skipping one letter from either string whenever the last letters differ.
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 length of the longest common SUBSTRING (contiguous) of "ABABCABBAC" and "BABCBACAB"?
- What is the minimum number of single-character insertions, deletions and substitutions needed to turn "sunday" into "saturnday"?
- What is the minimum number of characters you must delete from "abcbdaxyzyx" so that the remaining string is a palindrome?
- How many palindromic substrings (counted by position, so repeated text at different positions counts separately) does "abacabad" have? A…
- What is the minimum number of cuts needed to split "abbacdcdc" into pieces that are each a palindrome?
- What is the length of the shortest string that has both "abcbdab" and "bdcaba" as subsequences?