Three distinct phases and you have to get all of them right.
Model the problem as a simulation loop: repeatedly scan the board to mark all candies that are part of a horizontal or vertical run of 3 or more, remove them, then apply gravity by shifting candies down in each column. Continue until a full pass produces no removals, then return the board.
Pro tip: Clarify edge cases and constraints upfront (e.g., board dimensions, candy types, whether new candies spawn) and discuss time/space complexity, since interviewers at Roblox value production-ready thinking and clean, testable code.
Ask about board size, candy types, whether new candies appear after crushing, and if the board can be modified in place. Confirm the definition of a stable board.
Scan rows and columns to identify all candies that are part of a run of 3 or more. Use a boolean mask to mark them for removal, ensuring overlapping runs are handled correctly.
Remove marked candies (e.g., set to empty) and then apply gravity by shifting remaining candies down in each column, filling empty spaces at the top.
Repeat the crush and gravity steps until a full pass results in no removals. Return the final board.
Discuss time and space complexity, and walk through edge cases like empty board, no matches, and cascading matches. Suggest test cases.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.