358. Rearrange String k Distance Apart

Problem

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"
Hints
Related Problems

358. Rearrange String k Distance Apart

Rearrange a string so that identical characters are at least distance k apart, if possible.