#K5831. Palindrome Modification Challenge

    ID: 30614 Type: Default 1000ms 256MiB

Palindrome Modification Challenge

Palindrome Modification Challenge

Given an integer ( k ) and a string ( s ), your task is to determine whether it is possible to convert ( s ) into a palindrome by changing at most ( k ) characters. A string is a palindrome if it reads the same forwards and backwards. For each test case, if the number of mismatched pairs in ( s ) (i.e. the number of indices ( i ) such that ( s[i] \neq s[n-1-i] )) is less than or equal to ( k ), then the answer is YES; otherwise, the answer is NO.

Note: The number of mismatches is calculated only for the first half of the string. For example, for the string "abcd", there is one mismatch between 'a' and 'd' and between 'b' and 'c', but since we only consider one half, the effective mismatch count is computed accordingly.

inputFormat

The input will be given via standard input. The first line contains a single integer ( t ) denoting the number of test cases. ( t ) test cases follow. Each test case consists of a single line containing an integer ( k ) and a non-empty string ( s ) (without spaces), separated by a space.

outputFormat

For each test case, output a single line to standard output: print "YES" if it is possible to convert ( s ) into a palindrome by changing at most ( k ) characters, otherwise print "NO".## sample

3
1 abcd
2 abcca
0 racecar
NO

YES YES

</p>