Maximum Valid Substring Frequency
Updated
Problem statement
A valid substring of s is contiguous, has length from minLength through maxLength inclusive, and contains at most maxUnique distinct letters.
For this exercise, assume occurrences at different starting positions are counted separately, including overlapping occurrences. Return the largest occurrence count of any one valid substring value. Return 0 if no substring is valid. The result is a count, so no tie rule between equally frequent substring values is needed.
Function
maxSubstringFrequency(s: String, minLength: int, maxLength: int, maxUnique: int) → intExamples
Example 1
s = "aaaaa"minLength = 2maxLength = 3maxUnique = 1return = 4aa occurs at four starting positions, including overlaps. aaa occurs three times, so the answer is 4.
Example 2
s = "aabcabcaab"minLength = 3maxLength = 5maxUnique = 2return = 2aab occurs twice and uses only two distinct letters. It is a valid substring with the greatest frequency.
Example 3
s = "abc"minLength = 2maxLength = 2maxUnique = 1return = 0Both length-2 substrings contain two distinct letters and exceed the limit 1.
Constraints
1 <= s.length <= 10000;scontains lowercase English letters.1 <= minLength <= maxLength <= min(26, s.length).1 <= maxUnique <= 26.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Inventory Discount TrackerOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
Similar questions at other companies
- Perfect SubstringAXQ Capital · OA
- Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
- Longest Distinct StringSuperhuman · OASuperhuman interview questions
- Longest Substring Without Repeating CharactersAkuna Capital · OAAkuna Capital interview questions
- Perfect SubstringsVisa · OAVisa interview questions
- Vowel SubstringSnowflake · OASnowflake interview questions
- Count Distinct Fixed-Length SubstringsAdobe · OAAdobe interview questions
- Video ID Generation (Generic)TikTok · OATikTok interview questions
- Unaligned DedupeRubrik · OARubrik interview questions
- Get Max OccurrencesIBM · OAIBM interview questions