GATE Computer ScienceModerateGATE CS (PYQ pattern)
Characters may be added ONLY at the front of the string abacdcabxab. What is the minimum number of characters that must be added to make it a palindrome?
- A. 8
- B. 2
- C. 9
- D. 10
Correct answer: A. 8
Adding only at the front, we keep the longest palindromic prefix and mirror the rest in front. The longest palindromic prefix is aba (length 3), so 11 − 3 = 8 characters are needed. If insertions were allowed anywhere, 11 − LPS = 11 − 9 = 2 would suffice.
More Algorithms questions
- A digit string is decoded using A = 1, B = 2, …, Z = 26, and each code must be a valid letter number (so 0 is allowed only as part of 10…
- What is the maximum product of a non-empty contiguous subarray of [−2, 3, −4, 0, 5, −1, 2, −3, −1, 4]?
- The numbers 19, 5, 9, 18, 10, 29, 5, 24, 10 are split into two groups (every number goes into exactly one group). What is the smallest…
- A + or − sign is placed in front of each of the numbers 1, 1, 2, 3, 5, 8, 13, 21 (the two 1s are different items). In how many ways is the…
- An unbounded knapsack has capacity 47 and item types (weight, value): (5, 11), (8, 19), (9, 20), (13, 29), each available any number of…
- What is the largest sum of an increasing subsequence (strictly increasing, not necessarily contiguous) of [3, 100, 4, 5, 2, 200, 6, 7, 8…