FastPrepClicked One-Dimensional Candy Crush

Clicked One-Dimensional Candy Crush

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

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

Examples

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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String clickCandyCrush(String gems, int clickIndex) {
  // Write your code here.
}
gems"ABCCCBBBBCCCBBAAAB"
clickIndex5
expected"B"
Checking account…