One-Dimensional Candy Crush
Problem statement
Given a string s and an integer threshold k, repeatedly remove any maximal contiguous run of at least k equal characters.
Process runs from left to right. After a removal, the characters on its two sides become adjacent and may form a new qualifying run. Continue until no qualifying run remains, then return the remaining string.
Function
crushCandy(s: String, k: int) → StringExamples
Example 1
s = "aaabbbc"k = 3return = "c"Remove aaa, then remove the newly exposed run bbb.
Example 2
s = "aabbbacd"k = 3return = "cd"Removing bbb joins two and one a into aaa, which is removed next.
Example 3
s = "aabbccddeeedcba"k = 3return = ""Each removal exposes the next three-character run until the string is empty.
Constraints
0 <= s.length <= 10^5.2 <= k <= 10^5.scontains lowercase English letters.