Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 D
What is the minimum number of characters that must be inserted at the FRONT of "abaccabb" to make the whole string a palindrome?
- A. 2
- B. 7
- C. 6
- D. 5
Correct answer: C. 6
Find the longest suffix of s that is a palindrome (equivalently the longest palindromic prefix of reverse(s), computed with a prefix function). Adding one character per unmatched letter at the front is the answer. Using the longest palindromic subsequence instead counts a different quantity.
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 contiguous subarrays of [3, 4, -7, 1, 3, 3, 1, -4, 2] have sum exactly 7? Negative numbers are present.
- In "swissmississippi", what is the 0-based index of the first character that appears exactly once in the whole string?
- What is the length of the longest substring of "eceeebbaccbbaaceddccc" that contains AT MOST two distinct letters?
- In the list ['listen', 'silent', 'enlist', 'google', 'gooegl', 'cat', 'act', 'tac', 'dog'], how many unordered pairs of different…
- How many index pairs (i < j) of the list [1, 3, 2, 3, 4, 5, 3, 1, 2, 5] satisfy a[i] + a[j] = 6? Equal values at different positions count…
- How many unordered pairs of distinct positions in [2, 3, 4, 6, 8, 9, 12] have a product divisible by 6?