
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains a single integer ‘K’ denoting the distance between the same characters.
The second line of each test case contains a string ‘S’.
For each test case, print an integer 1 if it is possible to arrange the string else print 0.
The output for each test case is printed in a separate line.
1 <= T <= 5
1 <= N <= 5000
1 <= K <= N
Where ‘N’ is the length of the string ‘S’.
Time limit: 1 sec
You do not need to print anything. It has already been taken care of. Just implement the given function.
The idea here is to store each character’s next possible position in the map and then find for each index which characters among ‘a’ to ‘z’ will have the highest frequency and the next possible condition is less than this index. If we are unable to find any candidate for this then we return 0.
The function will take three parameters:
The idea here is to store all the frequency of the character and place the most frequent one first as close as possible, to extract out the character based on maximum frequency, we will be using max-heap (implemented using priority queue).