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|<=10^{5}

**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

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.

Vagesh Verma | 98 |

UrGuru | 98 |

chaolinyu | 84 |

prernaus24 | 83 |

devendrachoudhary5485 | 74 |

abducodes | 624 |

harshtyagi36 | 298 |

highway_to_hell | 252 |

rajeswarii | 248 |

arpit_anshuman | 240 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.