Most Frequent Valid Substring
Updated
Problem statement
You are given a string s and integers minLength, maxLength, and maxUnique.
A substring is valid when:
- its length is between
minLengthandmaxLength, inclusive, and - it contains at most
maxUniquedistinct characters.
Return the greatest number of occurrences of any one valid substring in s. Occurrences may overlap. Return 0 if no substring is valid.
Function
mostFrequentValidSubstring(s: String, minLength: int, maxLength: int, maxUnique: int) → intExamples
Example 1
s = "aababcaab"minLength = 2maxLength = 3maxUnique = 2return = 3The valid substring ab occurs three times, starting at indices 1, 3, and 7.
Example 2
s = "aaaa"minLength = 1maxLength = 3maxUnique = 1return = 4The length-one substring a is valid and occurs four times.
Constraints
1 <= s.length <= 1041 <= minLength <= maxLength <= s.length1 <= maxUnique <= 128scontains printable ASCII characters.
More Visa Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
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
- 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
- Find P-Matching ScoreAmazon · OA