#3853

Merge Close Characters

specialist · 820 · lc medium +31 · 54.1% accepted · 58 likes · top 46%

Description

Given a string s of lowercase English letters and an integer k, two identical characters in the current string are close if the distance between their indices is at most k. When a close pair is found, the right character merges into the left (the right occurrence is removed). Merges occur one at a time and the string updates after each; when multiple merges are possible, always pick the pair with the smallest left index (smallest right index to break ties). Return the string after no more merges are possible.

Code

1
2
3