#K2591. Most Frequent Substring Length
Most Frequent Substring Length
Most Frequent Substring Length
You are given n book titles. For each title, consider all distinct substrings of length \( k \). A substring qualifies if it appears in at least \( x \) different book titles. Your task is to determine if there is any qualifying substring. If such a substring exists, output \( k \); otherwise, output 0.
Note: A substring is a contiguous sequence of characters in a string. For each book title, the same substring should be counted at most once.
Formally, let \( T_i \) be the \( i \)-th title. For every substring \( s \) of length \( k \) in \( T_i \), if \( s \) appears in at least \( x \) different titles, the answer is \( k \); otherwise, the answer is 0.
inputFormat
The first line contains three space-separated integers: \( n \), \( k \), and \( x \), where \( n \) is the number of book titles, \( k \) is the length of the substrings to consider, and \( x \) is the minimum number of titles a substring must appear in.
This is followed by \( n \) lines, each containing one book title consisting of only lowercase letters.
outputFormat
Output a single integer: \( k \) if there exists at least one substring of length \( k \) that appears in at least \( x \) different titles; otherwise, output 0.
## sample5 3 2
thehobbit
alchemist
thegreatgatsby
thinkbig
thatboy
3