BETA

Difficulty Level: Easy

Submissions: 440 Accuracy:

37.73%

Minimum number of deletions.
         

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

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

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