Atmost K
Practice
4.5 (13 votes)
String algorithms
Algorithms
Hashing algorithm
Problem
57% Success 1447 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a string \(S\) of length \(N\) containing lowercase English letters and an integer \(K\). You can rearrange the characters of the string in any order. After that you split the string into several parts. Find the minimum number of parts in which you can split \(S\) such that each part satisfy the condition below:

  • The frequency of every unique character in the part is at most \(K\).

Input Format

  • The first line contains an integer \(T\), which denotes the number of test cases. For every test case:
  • The first line contains two space-separated integers \(N\) and \(K\).
  • The second line contains the string \(S\).

Output Format

For each test case, print the minimum number of parts in which you can split \(S\) such that each part satisfy the condition.

Constraints

\(1 \leq T \leq 10 \\ 1 \leq K \leq N \leq 10^5 \\ S \ \text{contains lowercase English letters}\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
369 votes
Tags:
Ad-HocString AlgorithmsHash functionEasyVery Easy
Points:20
1 votes
Tags:
Easy
Points:20
Tags:
mediumEasy