Data Structures & AlgorithmsHardGATE CS · ICPC regional
What is the length of the longest common SUBSTRING (contiguous) of "ABABCABBAC" and "BABCBACAB"?
- A. 7
- B. 6
- C. 3
- D. 4
Correct answer: D. 4
Let d[i][j] be the length of the common suffix ending at s[i] and t[j]. It resets to 0 on mismatch and extends by 1 on match, and the answer is the maximum d. Using the subsequence recurrence without the reset gives the wrong (larger) number.
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 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?
- How many DIFFERENT non-empty subsequences does the string "abcabc" have? Two subsequences are different if their letter sequences differ.