#K81552. Detecting Anagrams in Data Sets
Detecting Anagrams in Data Sets
Detecting Anagrams in Data Sets
You are given several data sets. Each data set consists of a list of strings. Your task is to determine whether any two strings in a data set are anagrams of each other.
Two words are anagrams if they contain exactly the same letters in a different order. Formally, for two strings \(s\) and \(t\), they are anagrams if \(sorted(s)=sorted(t)\), where the sorting is performed on the characters of the string.
For each data set, output YES
if there is at least one pair of anagrams; otherwise, output NO
.
The input is provided via standard input, and the output should be printed to standard output.
inputFormat
The first line contains a single integer \(T\) representing the number of data sets.
Each data set starts with an integer \(M\) on a new line, indicating the number of words in that data set, followed by a single line containing \(M\) words separated by spaces.
For example:
2 4 listen silent apple banana 3 cat act dog
outputFormat
For each data set, output a line containing YES
if the data set contains at least one pair of anagrams and NO
otherwise.
For the sample input above, the output would be:
YES YES## sample
2
4
listen silent apple banana
3
cat act dog
YES
YES
</p>