[Solution] Even Splits CodeChef Solution
Problem
You are given a binary string of length . You can perform the following operation on it:
- Pick any non-empty even-length subsequence of the string.
- Suppose the subsequence has length . Then, move the first characters to the beginning of and the other to the end of (without changing their order).
For example, suppose . Here are some moves you can make (the chosen subsequence is marked in red):
What is the lexicographically smallest string that can be obtained after performing this operation several (possibly, zero) times?
Note: A binary string is said to be lexicographically smaller than another binary string of the same length if there exists an index such that:
- and .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases. The description of the test cases follows.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer , the length of string .
- The second line contains a binary string of length .
Output Format
For each testcase, output a single line containing the lexicographically shortest binary string that can be obtained by performing the given operation several times.
Explanation:
Test case : There's only one move possible, and it gives back the original string when made. So, cannot be changed, and the answer is .
Test case : Make the following moves:
This is the lexicographically smallest string.
Test case : Performing any move doesn't change the string.
Test case : Make the move .
No comments:
Post a Comment