Bubble Explosion
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
TikTok reported this one in July 2026, and the detail that matters is in the first rule: a bubble explodes only if at least two of its side neighbors share its color. That's a simulation problem on a grid, not a flood fill. If you've got a TikTok OA coming up, expect a board up to 100 by 100, one explosion round, then gravity per column. It looks like a Candy Crush clone, but it's one pass with no chain reactions. StealthCoder is there as a safety net on the live OA if you blank, but the logic is short enough to own tonight.
The problem
You are given a rectangular board bubbles. Every cell contains a positive integer representing a bubble color. Two cells are neighbors only when they share a side. Perform exactly one simultaneous bubble explosion: A bubble is eligible to explode when at least two of its neighboring cells contain bubbles of the same color. Mark every eligible bubble and each of its same-colored neighboring bubbles. Remove all marked bubbles simultaneously. Within each column, let surviving bubbles fall downward while preserving their relative vertical order. Fill empty cells at the top with 0. Return the board after this single explosion and gravity step. Function bubbleExplosion(bubbles: int[][]) → int[][] Examples Example 1 bubbles = [[3,1,2,1],[1,1,1,4],[3,1,2,2],[3,3,3,4]] return = [[0,0,0,1],[0,0,0,4],[0,0,2,2],[3,0,2,4]] The eligible bubbles and their same-colored neighbors are removed at the same time. The remaining bubbles then fall to the bottom of their columns, and the newly empty cells are filled with 0. Constraints 1 <= bubbles.length <= 100 1 <= bubbles[0].length <= 100 1 <= bubbles[i][j] <= 10^4 Every row has the same length.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is reading the rules literally. Pass one: for every cell, count how many of its four neighbors share its color. If that count is 2 or more, mark the cell and mark those same-colored neighbors too. Write marks into a separate boolean grid, never into the board, because the explosion is simultaneous. Pass two: for each column, scan bottom to top, copy unmarked values down into a fresh column, and fill the leftover top cells with 0. The common pitfall is mutating the board mid-scan, which changes later neighbor checks. Another is looping the explosion until stable. The problem says exactly one. Bounds checks on edges trip people too. Total work is O(rows times cols). If your mind goes blank under the timer, StealthCoder can supply the two-pass skeleton live, but you can write it from this paragraph.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Bubble Explosion 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Bubble Explosion FAQ
What's the trick in the TikTok Bubble Explosion problem?+
Separate detection from removal. Scan the whole original board and record marks in a second grid. Only after every cell is checked do you remove anything. Mutating as you go breaks the simultaneous rule and gives wrong neighbor counts on later cells.
Do I need to repeat explosions until nothing changes?+
No. The statement says to perform exactly one simultaneous explosion, then one gravity step. Looping until stable is the most common over-engineering mistake. Do one marking pass, one gravity pass, return the board.
How do I mark the same-colored neighbors correctly?+
When a cell has two or more same-color side neighbors, mark it and also mark each of those neighbors. A neighbor may be marked by several cells, and that's fine since a boolean grid is idempotent. Don't mark neighbors of a different color.
How should I implement gravity per column?+
For each column, walk from the bottom row upward and write each unmarked bubble into the lowest free slot, keeping order. When you run out, fill the remaining top cells with 0. Use a new output grid so you don't overwrite values you still need.
How hard is this really, and how do I prepare in 48 hours?+
It's easy to medium. No fancy algorithm, just careful simulation on up to 100 by 100. Practice writing a four-direction neighbor check with bounds, then a column compaction. Hand-trace the sample board once. That covers nearly every bug.