# Mario and the Broken String || codechef solution

## Problem

Mario was going to gift Princess Peach a string $�$ of even length $�$.

Mario was clumsy and thus, broke the string in the middle. He now has two strings $�$ and $�$ such that $�=�\left[1,\frac{�}{2}\right]$ and $�=�\left[\frac{�}{2}+1,�\right]$.

Mario is not sure about the order in which he should join the strings $�$ and $�$ to get the string $�$. Thus, he joins the strings in any random order. Find whether it is guaranteed that Mario will get the same string $�$ if he joins the strings $�$ and $�$ in any order.

Note that $�\left[�,�\right]$ denotes a substring of string $�$ starting at index $�$ and having a length $\left(�-�+1\right)$.

### Input Format

• The first line of input will contain a single integer $�$, denoting the number of test cases.
• Each test case consists of two lines of input:
• The first line of each test case contains $�$ - the length of the initial string $�$.
• The second line contains the string $�$.

### Output Format

For each test case, print YES if it is guaranteed that Mario will get the same string $�$ irrespective of the order in which he joins the strings $�$ and $�$ and NO otherwise.

You may print each character of the string in uppercase or lowercase (for example, the strings YESyEsyes, and yeS will all be treated as identical).

### Constraints

• $1\le �\le 3000$
• $1\le �\le 1000$
• $�$ is even.
• $�$ consists of lowercase english alphabets.

### Sample 1:

Input
Output
4
6
abcabc
6
abcdef
4
aaaa
4
baab
YES
NO
YES
NO


### Explanation:

Test case $1$: On breaking, the string $�$ gives $�=���$ and $�=���$. Thus, joining it in either way $\left(��$ or $��\right)$, would give the same string $�$.

Test case $2$: On breaking, the string $�$ gives $�=���$ and $�=���$. Joining it as $��$ would give the string $������$ which is not equal to string $�$.

Test case $3$: On breaking, the string $�$ gives $�=��$ and $�=��$. Thus, joining it in either way $\left(��$ or $��\right)$, would give the same string $�$.

Test case $4$: On breaking, the string $�$ gives $�=��$ and $�=��$. Joining it as $��$ would give the string $����$ which is not equal to string $�$.

Code(c++):-

#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string a;
cin>>a;
int i=0,j=n/2;
int flag=0;
while(i<n/2)
{
if(a[i]!=a[j])
{
flag=1;
break;

}
i++,j++;
}
if(flag==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;

}

### Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-
iMocha coding Questions:-
Tech Mahindra coding questions:-
Unthinkable Solutions coding questions:-