FastPrepMost Frequent Valid Substring
Problems/Most Frequent Valid Substring

Most Frequent Valid Substring

Visa logoVisa● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A November 16, 2019 Visa Senior Software Engineer online assessment report gives the range of substring lengths, the limit on distinct characters, and the goal of the highest frequency. It leaves out limits, the alphabet, how overlaps work, and a function signature. Our version spells those out.

You are given a string s and integers minLength, maxLength, and maxUnique.

A substring is valid when:

  • its length is between minLength and maxLength, inclusive, and
  • it contains at most maxUnique distinct 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) → int

Examples

Example 1

s = "aababcaab"minLength = 2maxLength = 3maxUnique = 2return = 3

The valid substring ab occurs three times, starting at indices 1, 3, and 7.

Example 2

s = "aaaa"minLength = 1maxLength = 3maxUnique = 1return = 4

The length-one substring a is valid and occurs four times.

Constraints

  • 1 <= s.length <= 104
  • 1 <= minLength <= maxLength <= s.length
  • 1 <= maxUnique <= 128
  • s contains 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
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int mostFrequentValidSubstring(String s, int minLength, int maxLength, int maxUnique) {
        // Write your code here.
    }

}
Checking account…