One Swap to Palindrome

4.8

8 votes
Algorithms, Easy, Greedy Algorithms, Implementation, String Manipulation
Problem

You are given T tasks to perform. In each task, you are given a string S of length N. You are allowed to select any two indices i and j (i!=j) of the given string and perform exactly one swap between the characters at these indices.

If it is possible to make the new string a palindrome then print "Yes", else print "No".

Note:

A string is said to be palindrome if it reads same as its reverse form. For example: "madam" , "dad" etc.

 

INPUT

First line contain an integer T denoting total number of tasks to perform.

Each of the following T lines contains a string S.

 

OUTPUT

For each task, print a single line with "Yes" if it is possible to make palindrome otherwise print "No" without any quotes.

 

Constraints:

1T5
2N100000

String contains only lowercase English alphabets.

Sample Input
1
bbg

Sample Output
Yes
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

We can swap indices pair (1,2) [ 0-based ] , so that final string will be "bgb" which is a palindrome.

Editor Image

?