Data Structures & AlgorithmsHardGATE CS · ICPC regional
What is the length of the shortest string that has both "abcbdab" and "bdcaba" as subsequences?
- A. 9
- B. 13
- C. 4
- D. 7
Correct answer: A. 9
The shortest common supersequence keeps every common letter once and appends the remaining letters of each string: length = m + n − LCS. The LCS is the piece shared by both strings, so it is counted only once.
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
- How many DIFFERENT non-empty subsequences does the string "abcabc" have? Two subsequences are different if their letter sequences differ.
- How many subsequences (chosen by index) of "aabbabcaccb" spell exactly the word abc?
- Strings "ab" and "cde" are interleaved, keeping the internal order of each string. How many distinct strings can be formed this way?
- You may delete characters from "sea" and from "eat" to make the two strings equal. Deleting a character costs its ASCII code (for example…
- What is the length of the longest subsequence of [1, 7, 4, 9, 2, 5, 3, 8] whose consecutive differences alternate in sign (each step goes…
- How many contiguous subarrays of [1, 2, 3, 4, 7, 10, 13, 14, 15, 16] are arithmetic (at least 3 elements, with a constant difference…