#K48737. Anagram Pair Detection
Anagram Pair Detection
Anagram Pair Detection
You are given a series of test cases. In each test case, you are provided with a list of strings. Your task is to determine whether there exists at least one pair of distinct strings that are anagrams of each other.
An anagram is formed by rearranging the letters of a word to produce another word. Formally, two strings s and t are anagrams if and only if their sorted sequences of characters are identical, i.e. \(sorted(s)=sorted(t)\).
If an anagram pair is found in a test case, output YES
; otherwise, output NO
.
inputFormat
The input is provided via stdin in the following format:
- The first line contains an integer T, the number of test cases.
- For each test case, the first line contains an integer n denoting the number of strings.
- The next line contains n space-separated strings.
outputFormat
For each test case, output a single line on stdout that contains YES
if there exists at least one pair of anagrams, or NO
otherwise.
1
3
abc bca xyz
YES
</p>