Shortest Result After Candy Crush Removals
Problem statement
In one move, remove any maximal contiguous run of at least three equal characters. The remaining parts collide and may create new removable runs.
Return the shortest stable string reachable by choosing removal order optimally. Break equal-length ties lexicographically.
Function
shortestCandyCrush(text: String) → StringExamples
Example 1
text = "aaabbbacd"return = "cd"Removing bbb first creates aaaa, which is then removed.
Constraints
0 <= text.length <= 20.- The text contains lowercase English letters.