Leaderboard
Showing:
Minimum number of deletions.
Easy Accuracy: 47.11% Submissions: 3149 Points: 2

Given a string 'str' of size ‘n’. The task is to remove or delete minimum number of characters from the string so that the resultant string is palindrome.

Note: The order of characters should be maintained.

 

Input:

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the length of string str.

The second line of each test case contains the string str.


Output:

Print the minimum number of characters to be deleted to make the string a palindrome for each testcase in a new line.


Constraints:

1<= T <=100

1<= N <= 1000


Example:

Input:

1

7

aebcbda

Output:

2

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Minimum number of deletions.

Output Window