GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 22 May 2022

Palindromic Indices Codeforces Solution | Codeforces Problem Solution 2022

A. Palindromic Indices
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a palindromic string s of length n.

You have to count the number of indices i (1in) such that the string after removing si from s still remains a palindrome.

For example, consider s = "aba"

  1. If we remove s1 from s, the string becomes "ba" which is not a palindrome.
  2. If we remove s2 from s, the string becomes "aa" which is a palindrome.
  3. If we remove s3 from s, the string becomes "ab" which is not a palindrome.

Solution Click Below:-  CLICK HERE

Input

The input consists of multiple test cases. The first line of the input contains a single integer t (1t103)  — the number of test cases. Description of the test cases follows.

The first line of each testcase contains a single integer n (2n105)  — the length of string s.

The second line of each test case contains a string s consisting of lowercase English letters. It is guaranteed that s is a palindrome.

It is guaranteed that sum of n over all test cases does not exceed 2105.

Output

For each test case, output a single integer  — the number of indices i (1in) such that the string after removing si from s still remains a palindrome.

No comments:

Post a Comment