[Solution] Suspense String CodeChef Solution
Problem
Alice and Bob are playing a game with a binary string of length and an empty string .
They both take turns and Alice plays first.
- In Alice's turn, she picks the first character of string , appends the character to either the front or back of string and deletes the chosen character from string .
- In Bob's turn, he picks the last character of string , appends the character to either the front or back of string and deletes the chosen character from string .
The game stops when becomes empty.
Alice wants the resultant string to be lexicographically smallest, while Bob wants the resultant string to be lexicographically largest possible.
Find the resultant string , if both of them play optimally.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer - the length of the string .
👇👇👇👇👇
- The next line is the binary string .
Output Format
For each test case, print the the resultant string , if both of them play optimally.
Explanation:
Test case : Alice picks the first bit which is and appends it to the empty string . Bob then picks the last bit and appends it to the back of making the resultant string to be .
Test case :
- Alice picks and adds it to . Thus, becomes and becomes .
- Bob picks and adds it to front of . Thus, becomes and becomes .
- Alice picks and adds it to front of . Thus, becomes and becomes .
- Bob picks and adds it to back of . Thus, becomes empty and becomes .
No comments:
Post a Comment