← TikTok Interview Insights

TikTok·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

TikTok software engineer coding round, one problem the whole session. It was a game simulation question that looked manageable at first and then kept growing in scope as I talked through it.

Questions Asked (1)

Q1

Implement the core loop of a match-3 puzzle game (think Candy Crush): given an m×n grid, repeatedly detect runs of 3+ matching values horizontally or vertically, remove them all at once, apply gravity so cells fall down within each column, and keep looping until the board stabilizes. Return the final board and total cells removed across all passes.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This one spiraled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the rules first (match length, simultaneous removal, gravity, cascades), then outline a loop that marks all cells in runs of 3+ in both directions, removes them, applies gravity column-wise, and repeats until no matches remain. Emphasize correctness and complexity, and mention optimizations like run-length encoding or union-find if time permits.

Pro tip: Explicitly state that all matches in a pass must be removed simultaneously to avoid order-dependent bugs, and that gravity is applied per column after removal. This shows you understand the subtle correctness requirements that trip up many candidates.

1. Clarify rules and edge cases

Confirm match length (3+), whether matches are removed simultaneously, gravity direction, and handling of empty cells. Ask about board size limits and whether diagonal matches count.

2. Design match detection

Scan each row and column to find runs of 3+ identical non-empty values. Mark all cells in these runs for removal in a boolean grid to ensure simultaneous removal.

3. Remove and apply gravity

Remove all marked cells (set to empty), then for each column, compact non-empty cells downward while preserving order. Count removed cells.

4. Loop until stable

Repeat detection, removal, and gravity until a pass finds no matches. Return the final board and total removed count.

5. Analyze complexity and optimizations

Discuss time complexity O(passes * m * n) and space O(m * n). Mention possible optimizations like run-length encoding, union-find, or early termination if no matches.

Key Points to Mention

  • Simultaneous removal of all matches in a pass to avoid order-dependent errors
  • Column-wise gravity implementation (e.g., two-pointer compaction)
  • Loop termination condition: no matches found in a full scan
  • Time and space complexity analysis, including worst-case number of passes
  • Edge cases: empty board, no matches, full board of same value, single row/column
  • Potential optimizations: run-length encoding, union-find for connected components, or early exit

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.