Rearrange string as alternate x and y occurences
Submissions: 549   Accuracy:

25.41%

  Difficulty: Basic   Marks: 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

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Ashtputre
Author: saksham0751


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.