Clicked One-Dimensional Candy Crush
Problem statement
Click the zero-based position clickIndex in gems. If its maximal equal-character run has fewer than three gems, return the original string.
Otherwise remove that run. Whenever the two exposed boundary runs have the same character and their combined length is at least three, remove the combined run and continue outward. Return the final string.
Function
clickCandyCrush(gems: String, clickIndex: int) → StringExamples
Example 1
gems = "ABCCCBBBBCCCBBAAAB"clickIndex = 5return = "B"BBBB, then six Cs, then three Bs, then four As are removed in sequence.
Constraints
1 <= gems.length <= 10^5.0 <= clickIndex < gems.length.