#K75762. Anagram Pair Detection

    ID: 34492 Type: Default 1000ms 256MiB

Anagram Pair Detection

Anagram Pair Detection

In this problem, you are given T test cases. For each test case, you are provided an integer N followed by N strings. Your task is to determine whether there exists at least one pair of distinct strings that are anagrams of each other.

Two strings \(s_i\) and \(s_j\) are anagrams if \(\text{sorted}(s_i) = \text{sorted}(s_j)\). For example, "listen" and "silent" are anagrams because both yield \(elnist\) when sorted.

If such a pair exists for a test case, output YES; otherwise, output NO. Input is read from standard input and output is written to standard output.

inputFormat

The input starts with an integer T denoting the number of test cases.

For each test case:

  • The first line contains an integer N, the number of strings.
  • The second line contains N space-separated strings.

For example:

2
3
listen silent enlist
4
cat dog tac god

outputFormat

For each test case output a single line containing either YES if an anagram pair exists among the given strings, or NO otherwise.

For the sample input above, the output would be:

YES
YES
## sample
2
3
listen silent enlist
4
cat dog tac god
YES

YES

</p>