#C10116. Uniform Suffix Subset
Uniform Suffix Subset
Uniform Suffix Subset
You are given T test cases. In each test case, you are provided with an integer N denoting the number of words and an integer K denoting the length of the suffix to consider. Then, N words are given.
Your task is to determine whether it is possible to choose a subset of at least two words such that all the words in the subset share the same last K characters. In other words, check if there exists a suffix of length K that appears in at least two words.
If such a suffix exists, output YES
; otherwise, output NO
.
Note: If a word has length less than K, treat the entire word as its suffix.
inputFormat
The input is given through standard input (stdin) and follows the format below:
- The first line contains an integer T (1 ≤ T ≤ 100) denoting the number of test cases.
- For each test case:
- The first line contains two integers N and K (1 ≤ N ≤ 100, 1 ≤ K ≤ 100), where N is the number of words and K is the length of the suffix to consider.
- The second line contains N space-separated words. Each word consists of lowercase English letters.
outputFormat
For each test case, print a single line containing either YES
if there exists at least one suffix (of length K) that appears in at least two words, or NO
if no such suffix exists.
1
4 2
hello jello mellow yellow
YES
</p>