#C12463. Most Frequent Substrings of Length 3
Most Frequent Substrings of Length 3
Most Frequent Substrings of Length 3
Given a string, your task is to determine the most frequent substrings of length 3. If there are multiple substrings with the same highest frequency, return them in lexicographical (alphabetical) order.
Note: If the input string has less than 3 characters, the output should be empty.
The problem can be formalized as follows:
Given a string s, for every substring s[i:i+3] (where \(0 \le i \le |s|-3\)), count its frequency. Let \(F\) be the maximum frequency among these substrings. Output all substrings whose frequency equals \(F\), sorted in lexicographical order.
inputFormat
The input consists of a single line containing the string s. The string may include alphabets and other characters. Leading and trailing spaces are not significant.
outputFormat
Print the most frequent substrings of length 3 in lexicographical order separated by a single space. If no valid substring exists, print nothing.
## sampleababcabc
abc
</p>