-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathbase.java
More file actions
61 lines (52 loc) · 1.32 KB
/
Copy pathbase.java
File metadata and controls
61 lines (52 loc) · 1.32 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
53
54
55
56
57
58
59
60
61
package collectionFramework;
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int k = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
int flip = forPalindrome(s);
if(flip <= k){
if(s.length() %2 == 1){
System.out.println("YES");
}
else{
if((k-flip)%2 == 0){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
else{
System.out.println("NO");
}
}
sc.close();
}
public static int forPalindrome(String s){
int left = 0;
int right = s.length() - 1;
int flip = 0;
while(left < right){
for (int i =0;i<s.length()-1;i++){
if(s.charAt(left) != s.charAt(right)){
flip++;
}
left++;
right--;
}
}
return flip;
}
}