Back to problems

Maximum Number of Occurrences of a Substring (LC 1297)

Algorithm · Microsoft · Medium

You are given a string s and three integers: minLength, maxLength and maxUnique. Look at every substring of s whose length falls between minLength and maxLength (inclusive) and which contains no more than maxUnique different characters. Among all such substrings, find the one that appears most often in s, and return how many times it appears. Example 1: Explanation: Every qualifying substring occurs exactly once. Constraints: n, the length of s, is at most 1e5. maxLength <=…

Loading the rest of the question…