Minimum number of deletions.
Submissions: 887   Accuracy:

43.89%

  Difficulty: Easy   Marks: 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

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sujnesh Mishra
Author: sujnesh


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.