Longest sub-string having frequency of each char less than integer k
Easy Accuracy: 29.34% Submissions: 218 Points: 2

Given a string str of length n. The problem is to find the length of the longest sub-string in str having frequency of each character less than equal to the given value k.

INPUT : he first line consists of an integer T i.e. the number of test cases. First  line of each test case consists of an integer k. The second and last line of each test case consists of an string s.

OUTPUT : Print the length of the longest substring with frequency of each character is less than k.

CONSTRAINTS : 
1<=T<=100
1<=k,|Length of string|<=105

EXAMPLES :
INPUT:

2
1
babcaag
2
geeksforgeeks

OUTPUT :
3
10

EXPLAINATION :

Input : str = "babcaag", k = 1
Output : 3
abc and bca are the two longest
sub-strings having frequency of each character 
in them less than equal to '1'.

Input : str = "geeksforgeeks", k = 2
Output : 10

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.