InterviewDB Question

Most Frequent Substring of Length K - String Coding Round

Question Details

Problem Given a string s and an integer k, return the substring of length exactly k that appears most frequently. If there is a tie, return the lexicographically smallest one. Example: Approach Slide a window of size k across s, counting occurrences in a hash map. Track the max frequency and apply the lexicographic tiebreak in a single pass. Time: O(n*k) naive, O(n) with rolling hash. Follow-ups How would you handle the case where k equals len(s)? Extend to return the top-3 most frequent substri…

Full Details

🔒

Unlock all Hubspot questions

Full insider details, leaked discussions, and candidate experiences.

Get full access — $100 a year, unlimited access

About This Question

This is a reported interview question from a hubspot interview during the onsite round.

It covers the following topics: Coding, Hash Table, Strings, Onsite .