[Solution] Binary Base Basics solution codechef

Binary Base Basics solution codechef – You are given a binary string SS and an integer KK. In one operation, you can pick any bit and flip it, i.e turn 00 to 11 or 11 to 00. Can you make the string SS a palindrome using exactly KK operations?

Print YES if this is possible, and NO if it is not.

Input Format

  • The first line of input contains one integer TT, denoting the number of test cases. The description of TT test cases follows.
  • Each test case consists of two lines of input.
    • The first line of each test case contains two space-separated integers NN and KK, denoting the length of the binary string and the number of operations to be performed.
    • The second line contains the binary string SS.

Output Format

For each test case, print the answer on a new line — YES if the SS can be made a palindrome using exactly KK operations, and NO otherwise.

You may print each character of YES and NO in either uppercase or lowercase (for example, yesyEsYes will all be considered identical).


  • 1T10001≤T≤1000
  • 1N10001≤N≤1000
  • 0KN0≤K≤N
  • SS is a binary string, i.e, contains only characters 00 and 11


Subtask #1 (100 points): Original constraints

Sample Input 1 

3 0
6 1

Sample Output 1 



Test case 11: SS is not a palindrome, and no operations can be performed on it because K=0K=0.

Test case 22: Flip the first bit to obtain S=001100S=001100, which is a palindrome.

Leave a Comment