Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
What is the minimum number of characters you must delete from "abcbdaxyzyx" so that the remaining string is a palindrome?
- A. 10
- B. 6
- C. 5
- D. 9
Correct answer: B. 6
The kept characters form a palindromic subsequence, so the answer is n − LPS = 11 − 5 = 6 (for example keep xyzyx or abcba). Printing the LPS length itself gives 5; 9 keeps only a matching pair and 10 a single character.
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 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.
- 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?