kikit
7/5/2016 - 12:55 PM

Palindromic Subsequences - GeeksforGeeks

Palindromic Subsequences - GeeksforGeeks

/*
http://ideone.com/oUPCxR
http://www.geeksforgeeks.org/minimum-number-of-palindromic-subsequences-to-be-removed-to-empty-a-binary-string/
http://www.practice.geeksforgeeks.org/problem-page.php?pid=718
*/

#include <iostream>
#include <string>
#include <vector>
using namespace std; 

bool isPalindrome(string s, int len){
	int l = 0;
	int h = len -1;
	
	while(l < h){
		if(s[l++] != s[h--])
			return false;
	}
	return true;
}
int main() {
	int t, n;
	cin >> t;
	while(t--){
		string s;
		cin >> n >> s;
		if(isPalindrome(s, n))
			cout << 1 << endl;
		else
			cout << 2 << endl;
		
	}
	return 0;
}