#K256. Contiguous Subsequence Score
Contiguous Subsequence Score
Contiguous Subsequence Score
You are given a word and an integer K. Your task is to determine whether there exists a contiguous subsequence (substring) of the word such that the sum of the scores of its characters is exactly K. The score for each character c is defined as:
\( score(c) = \text{ord}(c) - \text{ord}('a') + 1 \)
For example, the score of 'a' is 1, 'b' is 2, and so on. You need to answer YES
if there exists such a contiguous subsequence and NO
otherwise.
The input begins with an integer T, representing the number of test cases. Each test case consists of three values: an integer N (the length of the word), the word itself (a string of lowercase letters), and the target integer K.
For each test case, output the result on a new line.
inputFormat
The first line contains an integer T, denoting the number of test cases.
Each of the following T lines contains a test case with three space-separated values: an integer N (the length of the word), a string S (the word), and an integer K (the target score).
Example:
2 3 abc 6 5 zyxwv 15
outputFormat
For each test case, print a single line with either YES
if a contiguous subsequence with the given score exists, or NO
otherwise.
Example:
YES NO## sample
2
3 abc 6
5 zyxwv 15
YES
NO
</p>