-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryBaseBasics-CCQ.cpp
More file actions
52 lines (43 loc) · 1 KB
/
BinaryBaseBasics-CCQ.cpp
File metadata and controls
52 lines (43 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
You are given a binary string S and an integer K. In one operation, you can pick any bit and flip it, i.e turn 0 to 1 or 1 to 0.
Can you make the string S a palindrome using exactly K operations?
Print YES if this is possible, and NO if it is not
Input :
2
3 0
110
6 1
101100
Output :
NO
YES
Explanation
Test case 1: S is not a palindrome, and no operations can be performed on it because K=0.
Test case 2: Flip the first bit to obtain S=001100, which is a palindrome.
*/
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int len,k,count=0;
cin>>len>>k;
string s;
cin>>s;
for(int i=0;i<len/2;i++){
if(s[i]!=s[len-i-1]){
count+=1;
}
}
if(k>=count){
if((k-count)%2==0) cout<<"YES"<<endl;
else if(len%2!=0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
return 0;
}