Bi_lindrome!
Difficulty Rating:1095 @Codechef
Problem
You are given a string of length .
Your task is to delete a subsequence of maximum length from the string, such that, after concatenating the remaining parts of the string, it becomes a palindrome of length greater than .
If this is possible, print the maximum length of the subsequence that can be deleted. Otherwise, print .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of lines of input:
- The first line consists the a single integer - the length of string .
- The second line contains string , consisting of lowercase english alphabets.
Output Format
For each test case, if it is possible to delete a subsequence under the given conditions, print a single integer, denoting the maximum length of the subsequence that can be deleted. Otherwise, print .
Constraints
- consists of lowercase english alphabets.
Sample 1:
Explanation:
Test case : Possible ways to delete a subsequence are:
- Delete subsequence
khjto get palindromebab. - Delete subsequence
akhjto get palindromebb.
The subsequence having maximum length that can be deleted is akhj, having length .
Test case : We cannot delete any subsequence under the given conditions.
Test case : We can delete the subsequence qt to obtain the string oo, which is a palindrome. This is the only subsequence that can be deleted and it has length .
No comments:
Post a Comment