[Solution] Palindrome Flipping CodeChef Solution
Problem
Chef has a binary string of length .
In one operation, Chef can:
- Select two indices and and flip and . (i.e. change to and to )
For example, if and chef applys operation on and then: .
Find if it is possible to convert to a palindrome by applying the above operation any (possibly zero) number of times.
Note: A string is called a palindrome if it reads the same backwards and forwards, for e.g. and are palindromic strings.
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer — the length of the binary string .
- The second line of each test case contains a binary string of length containing s and s only.
Output Format
For each test case, output YES
if it is possible to convert to a palindrome. Otherwise, output NO
.
You can print each character of the string in uppercase or lowercase. For example, the strings YES
, yes
, Yes
,
and yEs
are all considered the same.
Explanation:
Test case 1: We can perform the following operation:
- Select and . Then , which is a palindrome.
Test case 2: It can be proven that we can not make a palindrome using the given operation.
Test case 3: We can perform the following operations:
- Select and . Then
- Select and . Then , which is a palindrome.
No comments:
Post a Comment