Rearrange string as alternate x and y occurences
Basic Accuracy: 23.99% Submissions: 680 Points: 1

Given a binary string s and two integers x and y. Arrange the given string in such a way so that '0' comes X-times then '1' comes Y-times and so on until one of the '0' or '1' is finished. Then concatenate rest of the string and print the final string.

Input:
The first line consists of an integer T i.e number of test cases. The first line of each test case consists of two integers x and y.Then next line consists of a string s.

Output:
Print the required answer.

Constraints: 
1<=T<=100
1<=|Length of string|<=10000
1<=x,y<=1000

Example:
Input:

2
1 1
0011
1 1
1011011

Output:
0101
0101111

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.