Rearrange a string so that identical characters are at least distance k apart, if possible.
Given a string s and an integer k, rearrange the string so that any two identical characters are at least k positions apart. Return any valid rearrangement, or an empty string if no valid rearrangement exists.
When k <= 1, every permutation already satisfies the distance requirement, so the input string itself is a valid answer.
Examples
Input:["aabb",2]
Output:"abab"
Input:["aaabc",3]
Output:""
Hints
Use a max-heap to always pick the most frequent character.
Use a queue to keep track of characters that were recently used.
Only add characters back to the heap when they've had k distance.