Showing:
Handle Score
@Ibrahim Nash 5761
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Construct binary palindrome by repeated appending and trimming
Medium Accuracy: 40.0% Submissions: 5 Points: 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.

Example 1:

â€‹Input : N = 5 and K = 3
Output : 11011
Explanation:
The 3 sized substring is 110 combined
twice and trimming the extra 0 in the
end to give 11011.


â€‹Example 2:

Input : N = 2 and  K = 8
Output :  11 

This is a function problem. The input is already taken care of by the driver code. You only need to complete the function binaryPalindrome() that takes two integers N, K and return the output is a palindrome of size N. The driver code takes care of the printing.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

Constraints:
1 ≤ N ≤ 105
1 ≤ K ≤ 105

### Editorial

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

#### My Submissions:

Construct binary palindrome by repeated appending and trimming