


‘S’ = “bacda” and ‘K’ = 3.
So, the substrings having at most ‘3’ distinct characters are called good substrings. Some possible good substrings are:
1. “bac”
2. “acd”
3. “acda”
The substring “acda” is the largest possible good substring, as we cannot get any other substring of length 5 or more having distinct characters less than or equal to ‘3’. Thus, you should return ‘4’ as the answer.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains a single integer ‘K’, denoting the maximum number of distinct characters.
The second line of each test case contains a string ‘S’
For each test case, print a single line containing an integer denoting the length of the longest substring that contains at most 'K' distinct characters.
The output of each test case will be printed in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= K <= 26
1 <= N <= 10^4
All the characters of the string are lowercase English alphabet letters.
Time Limit: 1 sec
Finally, return ‘longestLength’, which has our required answer.
Now, after the binary search, we will have our required answer in the variable ‘longestLength’.