Company: Axis_bank_22nov
Difficulty: medium
Problem Description You are given a string S consisting of lower-case letters and an integer K. Your task is to maximize and return an integer value representing the length L, where L is the length of a substring such that all substrings of String S with length L have at most K distinct characters. Note: A substring is a contiguous sequence of characters within a string. Input Specification input1: An integer value denoting the length of string S. input2: An integer value K. input3: The string S. Output Specification Return an integer value representing the maximum value of length L. Examples Example 1 Input: input1 = 9, input2 = 2, input3 = "baaabbcca" Output: 3 Explanation: In the string baaabbcca, the substrings of length 2 (L = 2) are: {ba, aa, aa, ab, bb, bc, cc, ca}. All of them have at most 2 distinct elements. The objective is to maximize L; therefore, we will check for substrings of length 3 (L = 3): {baa, aaa, aab, abb, bbc, bcc, cca}. In this case, all of them have at most 2