#C7738. Longest Concatenated Word Length
Longest Concatenated Word Length
Longest Concatenated Word Length
You are given a list of words. Your task is to find the maximum length among all words that can be formed by concatenating at least two other words from the list.
A word is considered to be formed by concatenation if it can be split into two or more parts, each of which is a word present in the list. Note that the parts used for concatenation must be non-empty, and a word cannot be used as its own component in the formation.
If no such word exists, print 0
.
Note: The input will be read from standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The first line contains an integer N representing the number of words. The next N lines each contain a word.
Example:
6 cat bat rat catbat batcat catrat
outputFormat
Print a single integer which is the length of the longest word that can be formed by concatenating other words from the list. If no such word exists, print 0
.
1
cat
0
</p>