One Swap to Palindrome
Practice
4.8 (8 votes)
Algorithms
Easy
Greedy algorithms
Implementation
String manipulation
Problem
81% Success 10661 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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:

\(1 \le T \le 5\)
\(2 \le N \le 100000\)

String contains only lowercase English alphabets.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
23 votes
Tags:
Basics of Greedy AlgorithmsAlgorithmsGreedy Algorithms
Points:20
12 votes
Tags:
AlgorithmsEasyGreedy AlgorithmsString Manipulationsorting
Points:30
16 votes
Tags:
ApprovedBasic ProgrammingImplementationMediumOpenRecursionTwo dimensional