Minimum Length After Spacing Equal Characters
Problem statement
Given a non-empty string of lowercase English letters and a nonnegative integer k, rearrange all characters and insert any number of placeholder positions so that every two equal characters have at least k positions between them.
Return the minimum possible total sequence length, including placeholders. The output asks only for the length, not one arrangement.
Function
minimumRearrangedLength(characters: String, k: int) → longExamples
Example 1
characters = "abaaab"k = 3return = 13Four copies of a require three groups of at least three separating positions.
Example 2
characters = "abaacd"k = 4return = 11Three copies of a force a span of 11 positions.
Constraints
1 <= characters.length <= 200000characterscontains only lowercase English letters.0 <= k <= 10^9- The answer fits in a signed 64-bit integer.
Source note: Interview prompt excerpt preserved as source evidence.