FastPrepFastPrep
Problem Brief

Max Frequency Substring

OA
See Snowflake online assessment and hiring insights

Given a string containing a number of characters, find the substrings within the string that satisfy the conditions below:

  • The substring's length should be in the inclusive interval (minLength, maxLength).
  • The total number of unique characters should not exceed maxUnique.
  • Using those conditions, determine the frequency of the maximum occurring substring.

    Function Description

    Complete the function getMaxFrequencySubstring in the editor.

    getMaxFrequencySubstring has the following parameters:

    1. String s: the string to analyze
    2. int minLength: the minimum length of the substring
    3. int maxLength: the maximum length of the substring
    4. int maxUnique: the maximum number of unique characters in the substring

    Returns

    int: the frequency of the maximum occurring substring

    1Example 1

    Input
    s = "abcde", minLength = 2, maxLength = 3, maxUnique = 3
    Output
    1
    Explanation
    The given string components is 'abcde'. The number of pieces in an interval should be greater than or equal to minLength = 2, so 'a', 'b', 'c', 'd', and 'e' are discarded. The combination of characters should be less than or equal to maxLength = 3, so 'abcd', 'bcde', and 'abcde' are discarded. The intervals that satisfy the conditions above are 'ab', 'bc', 'cd', 'de', 'abc', 'bcd', and 'cde'. Each combination of characters occurs only one time, so the maximum number of occurrences is 1.

    Constraints

    Limits and guarantees your solution can rely on.

    An unknown urban legend for now 🥲
    public int getMaxFrequencySubstring(String s, int minLength, int maxLength, int maxUnique) {
        // write your code here
    }
    
    Input

    s

    "abcde"

    minLength

    2

    maxLength

    3

    maxUnique

    3

    Output

    1

    Sign in to submit your solution.