Clear Matching Tiles on a Prime Gaming Puzzle Board Until Stable

Last updated: November 29, 2026

Quick Overview

A match-three puzzle board for a Prime Gaming promotion is an m by n grid of positive tile IDs, with 0 meaning empty. Repeatedly crush every horizontal or vertical run of three or more equal tiles at the same time, let tiles above fall into the gaps, and stop when no runs remain. Return the stable board.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A match-three puzzle board for a Prime Gaming promotion is an m by n grid of positive tile IDs, with 0 meaning empty. Repeatedly crush every horizontal or vertical run of three or more equal tiles at the same time, let tiles above fall into the gaps, and stop when no runs remain. Return the stable board.

An Amazon onsite simulation question where the interviewer checks careful phase separation: mark all runs first, then crush, then apply gravity, then repeat. Overlapping runs (an L or T shape) must be crushed together, which breaks naive one-run-at-a-time code.

What the Interviewer Expects
  • Marks all runs in a pass before removing anything
  • Handles overlapping horizontal and vertical runs
  • Applies gravity column by column with a write pointer
  • Loops until a pass marks nothing
  • Bounds the number of rounds
Key Topics to Cover
matrix simulation
multi-phase updates
gravity compaction
fixed point iteration
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Count the score where each crushed tile is worth its ID.
  • How would you speed this up for a 1000 by 1000 board?
  • Detect whether any single swap could create a run.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: grid of non-negative integers, 0 is empty. Output: the final grid after repeated crush and drop rounds. All runs found in one round are crushed simultaneously....

High-Level Design

Each round has three phases. Mark: scan every horizontal window of three and every vertical window of three; if all three are equal and nonzero, mark them. Using a separate boolean set (rather than ne...


Submit Your Answer
Markdown supported