Company: Texas

Difficulty: medium

Problem Statement

Most Frequent N-gram Given a string `S` and an integer `N`, consider every contiguous substring of `S` having length `N`. Print the N-gram that occurs most often and its number of occurrences. If several N-grams have the same highest frequency, print the one whose first occurrence in `S` is earliest. Input Format One line contains `S` and `N`, separated by whitespace. Output Format Print the selected N-gram followed by its frequency, separated by one space. Constraints - `1 <= |S| <= 100` - `1 <= N <= 10` - `N <= |S|` Examples ### Example 1 Input banana 3 Output ana 2 ### Example 2 Input isamohanaismohana 3 Output moh 2 Notes N-grams may overlap. In a frequency tie, the earliest N-gram in the original string wins.

More Texas OA questionsInterview experiences