Construct binary palindrome by repeated appending and trimming
Submissions: 1135   Accuracy:

42.46%

  Difficulty: Medium   Marks: 4

Given n and k, Construct a palindrome of size n using a binary number of size k repeating itself to wrap into the palindrome. The palindrome must always begin with 1 and contains the maximum number of zeros.

Input:
The first line contains an integer T, the number of test cases. For each test case, there are two integers n & k.

Output:
For each test case, the output is a palindrome of size n.

Constraints:
1<=T<=100
1<=n<=‚Äč10^3
1<=k<=10^3

Example:
Input

2
5 3
2 8
Output
11011
11

Explanation:
1.
The 3 sized substring is 110 combined twice and trimming the extra 0 in the end to give 11011.
2.  The 8 sized substring is 11...... wrapped to two places to give 11.

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

Contributor: Vanshika
Author: Vanshika_pec


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.