#C14402. Most Common Substring
Most Common Substring
Most Common Substring
You are given a list of strings. Your task is to compute all contiguous substrings of length at least 2 from each string and count their frequencies across the entire list. Output the substring that appears most frequently. In case of a tie, output the lexicographically smallest substring. If there is no substring of length at least 2 (for example, when the list is empty or all strings are of length 1), output an empty string.
Note: A substring is a contiguous sequence of characters within a string.
Example:
Input: 3 abcab bca cab</p>Output: ab
inputFormat
The input is given via stdin and has the following format:
n s1 s2 ... sn
Where n
(an integer) represents the number of strings, and each of the following n
lines contains a non-empty string.
outputFormat
Output a single line to stdout containing the most common substring of length at least 2. If there are multiple substrings tied with the highest frequency, output the lexicographically smallest one. If no valid substring exists, output an empty string.
## sample3
abcab
bca
cab
ab