Clicked One-Dimensional Candy Crush
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Bloomberg reportedly asked this one in July 2020, and it looks like a Candy Crush simulation but it's really a run-length problem with a cascade. Find the run at clickIndex, check if it's at least three, delete it, then keep merging the neighbors outward. If you're taking the OA in a day or two, the trick is to stop thinking about strings and think about runs. StealthCoder is there as a safety net on the live OA if your mind goes blank on the outward merge loop, but the logic is small enough to own yourself.
The problem
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 = 5 return = "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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The whole problem reduces to two pointers expanding outward from the clicked run. First, expand left and right from clickIndex while characters match to get the run [l, r]. If its length is under 3, return the original string. Otherwise set l to the left boundary and r to the right boundary, then remove the run. Now the exposed neighbors are the run ending at l-1 and the run starting at r+1. If they share a character and their combined length is at least 3, remove both and move outward again. Stop otherwise. Never build new strings in the loop, because with 10^5 characters that's quadratic. Track indices only, then slice once at the end. The common pitfall is merging neighbors whose characters differ, or merging when the combined count is under 3. Also remember a neighbor run must be measured in full, not one character. The whole thing is O(n).
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Clicked One-Dimensional Candy Crush cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Clicked One-Dimensional Candy Crush FAQ
What's the trick in Clicked One-Dimensional Candy Crush?+
Work with indices, not string edits. Expand from clickIndex to find the run, then loop outward measuring the full left and right neighbor runs. If the characters match and the combined length is at least 3, widen the removal range. Build the answer once at the end.
How hard is this Bloomberg OA question really?+
Medium at most. There's no fancy data structure. The difficulty is careful boundary handling and avoiding repeated string rebuilds. With a 10^5 length cap, an O(n) pointer approach passes and a naive repeated-concatenation approach is the one that risks timing out.
What edge cases should I test?+
Test a click on a run shorter than three, which returns the original string. Test a removal that clears the whole string, which returns empty. Test neighbors with different characters, which stop the cascade. Test neighbors that match but combine to fewer than three, which also stops it.
Do I need a stack for this?+
No. A stack fits the classic repeated-crush version, but here only one click cascades outward from a single point. Two pointers expanding left and right is simpler and keeps the solution O(n) time with O(1) extra space beyond the output.
How do I prepare in 48 hours for this kind of problem?+
Write the run-expansion helper from scratch twice. Then hand-trace the sample, ABCCCBBBBCCCBBAAAB clicked at index 5, until the outward cascade feels automatic. Focus on index bookkeeping, since that's where most wrong answers come from.