#C8287. Anagram Subword Pair
Anagram Subword Pair
Anagram Subword Pair
You are given a list of words. A subword is defined as any contiguous substring of a word. The task is to determine if there exists at least one pair of subwords, coming from different words, that are anagrams of each other. Two subwords are anagrams if their characters can be rearranged to form each other. If such a pair exists, print True
; otherwise, print False
.
Note: Even a single occurrence of a matching anagram pair is sufficient to output True
. The input words can be empty, and a subword is considered only if it is non-empty.
The solution should read the input from standard input (stdin
) and write the result to standard output (stdout
).
inputFormat
The input is given via stdin and has the following format:
N word1 word2 ... wordN
Where N
is an integer representing the number of words, and each of the next N
lines contains a word (possibly empty).
outputFormat
Output a single line to stdout containing either True
or False
depending on whether or not a pair of non-overlapping subwords from different words that are anagrams exists.
4
listen
silent
enlist
google
True