#C4537. Longest Chain Word Finder
Longest Chain Word Finder
Longest Chain Word Finder
You are given a list of words. Your task is to find the longest word that can be constructed by chaining words together. In a valid chain, each subsequent word must start with the last letter of the previous word. For example, if the chain starts with cat, then the next word must begin with t.
If there are multiple valid chains, output the one whose final word has the maximum length. In case of a tie, output the first one found. Note that a word may only appear once in the chain.
Note: All formulas or constraints, if any, should be displayed using LaTeX. In this problem there is no explicit formula.
inputFormat
The first line of input is an integer n which denotes the number of words. The following n lines each contain a single word consisting of lowercase English letters.
outputFormat
Print to standard output the longest word (by character length) that can be constructed by chaining the given words. Each subsequent word in the chain must start with the last letter of the previous word. If multiple words qualify, output the first one found.
## sample1
word
word
</p>