[Solution] 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 and .
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 denotes a substring of string starting at index and having a length .
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 YES
, yEs
, yes
, and yeS
will all be treated as identical).
Explanation:
Test case : On breaking, the string gives and . Thus, joining it in either way or , would give the same string .
Test case : On breaking, the string gives and . Joining it as would give the string which is not equal to string .
Test case : On breaking, the string gives and . Thus, joining it in either way or , would give the same string .
Test case : On breaking, the string gives and . Joining it as would give the string which is not equal to string .
No comments:
Post a Comment