FastPrepShortest Result After Candy Crush Removals

Shortest Result After Candy Crush Removals

Bloomberg LP logoBloomberg LP● HardFULLTIMENEW GRADPHONE SCREEN
Learn

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) → String

Examples

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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String shortestCandyCrush(String text) {
  // Write your code here.
}
text"aaabbbacd"
expected"cd"
Checking account…