#C5635. Palindromic Substrings Within Constraints

    ID: 49306 Type: Default 1000ms 256MiB

Palindromic Substrings Within Constraints

Palindromic Substrings Within Constraints

Given an integer N representing the length of a string S, an integer K which specifies the maximum substring length to be checked, and the string S itself, determine whether there exists a palindromic substring in S whose length is at least 2 and at most K. A palindrome is a string that reads the same forwards and backwards. In mathematical terms, a string T of length l is a palindrome if it satisfies \(T[i] = T[l-i+1]\) for all \(1 \leq i \leq l\).

If such a substring exists, output "YES"; otherwise, output "NO".

Note: The input is read from standard input (stdin) and the output should be written to standard output (stdout).

inputFormat

The input begins with an integer T denoting the number of test cases. For each test case, the first line contains two integers N and K, where N is the length of the string and K is the maximum length of the substring to check. The second line of each test case contains the string S consisting of lowercase English letters.

Example:

3
5 3
ababa
6 2
abcdef
4 4
abccba

outputFormat

For each test case, output a single line containing "YES" if there exists a palindromic substring of length between 2 and K (inclusive) in the string S; otherwise, output "NO".

Example:

YES
NO
YES
## sample
3
5 3
ababa
6 2
abcdef
4 4
abccba
YES

NO YES

</p>