4019. Merge Close Characters II
You are given a string
sconsisting of lowercase English letters and an integerk.Two equal characters
s[i]ands[j], where0 <= i < j < s.length, are considered close ifj - i <= k. All indices refer to the current string.Repeatedly perform the following operation until no close pair remains:
- Among all close pairs
(i, j), choose the pair with the smallesti. If multiple pairs have the samei, choose the one with the smallestj.- Merge the right character into the left character by removing
s[j]froms. The characters[i]remains unchanged, and the remaining characters are reindexed.Return the resulting string after performing all possible merges.
1 | class Solution { |