Longest sub-string having frequency of each char less than integer k
Submissions: 190   Accuracy:

26.31%

  Difficulty: Easy   Marks: 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

** For More Input/Output Examples Use 'Expected Output' option **

Author: saksham0751


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.