Find every tile in a horizontal or vertical run of 3 or more on a match-3 board

Quick Overview

Scan a match-3 game board and return the coordinates of every tile that belongs to a horizontal or vertical run of three or more identical tiles, sorted and without duplicates. It tests run detection in a matrix, handling tiles shared by two matches, and producing a deterministic output order.

Find every tile in a horizontal or vertical run of 3 or more on a match-3 board

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given an `m x n` `board` of integers where each integer represents a tile type. Identify all tiles that are part of a horizontal or vertical match of 3 or more consecutive identical tiles. A match is 3 or more consecutive tiles of the same type in a single row (horizontal) or a single column (vertical). Return a sorted list of `[row, col]` coordinates of all matched tiles. Each coordinate appears at most once, even if a tile is part of both a horizontal and a vertical match. ### Function Signature ```python def find_matches(board: list[list[int]]) -> list[list[int]]: ``` ### Rules - Coordinates are 0-indexed. Row 0 is the top row and column 0 is the leftmost column. - Sort the result by row ascending, then by column ascending. - Only horizontal and vertical runs count. Diagonal runs are not matches. - If no tile is part of a match, return an empty list. ### Constraints - `3 <= m, n <= 50` - `1 <= board[i][j] <= 9` ### Examples ```text Input: board = [ [1,1,1,2,3], [2,2,2,2,3], [3,4,5,6,3] ] Output: [[0,0],[0,1],[0,2],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,4]] ``` Row 0 starts with three 1s and row 1 starts with four 2s, so both are horizontal matches. Column 4 holds three 3s, a vertical match. Tile `[1,4]` has value 3, so it belongs only to the vertical match, since the run of 2s in row 1 stops at column 3. ```text Input: board = [ [1,2,3], [4,2,6], [7,2,9], [1,2,3] ] Output: [[0,1],[1,1],[2,1],[3,1]] ``` Column 1 has four consecutive 2s, a vertical match of length 4. No row has three consecutive equal tiles. ```text Input: board = [ [5,1,5], [1,1,1], [5,1,5] ] Output: [[0,1],[1,0],[1,1],[1,2],[2,1]] ``` Row 1 and column 1 are both runs of three 1s. Tile `[1,1]` is in both matches and is listed once.

Overview: Scan a match-3 game board and return the coordinates of every tile that belongs to a horizontal or vertical run of three or more identical tiles, sorted and without duplicates. It tests run detection in a matrix, handling tiles shared by two matches, and producing a deterministic output order.

Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given an m x n board of integers where each integer represents a tile type. Identify all tiles that are part of a horizontal or vertical match of 3 or more consecutive identical tiles.

A match is 3 or more consecutive tiles of the same type in a single row (horizontal) or a single column (vertical).

Return a sorted list of [row, col] coordinates of all matched tiles. Each coordinate appears at most once, even if a tile is part of both a horizontal and a vertical match.

Function Signature

def find_matches(board: list[list[int]]) -> list[list[int]]:

Rules

  • Coordinates are 0-indexed. Row 0 is the top row and column 0 is the leftmost column.
  • Sort the result by row ascending, then by column ascending.
  • Only horizontal and vertical runs count. Diagonal runs are not matches.
  • If no tile is part of a match, return an empty list.

Constraints

  • 3 <= m, n <= 50
  • 1 <= board[i][j] <= 9

Examples

Input: board = [
  [1,1,1,2,3],
  [2,2,2,2,3],
  [3,4,5,6,3]
]
Output: [[0,0],[0,1],[0,2],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,4]]

Row 0 starts with three 1s and row 1 starts with four 2s, so both are horizontal matches. Column 4 holds three 3s, a vertical match. Tile [1,4] has value 3, so it belongs only to the vertical match, since the run of 2s in row 1 stops at column 3.

Input: board = [
  [1,2,3],
  [4,2,6],
  [7,2,9],
  [1,2,3]
]
Output: [[0,1],[1,1],[2,1],[3,1]]

Column 1 has four consecutive 2s, a vertical match of length 4. No row has three consecutive equal tiles.

Input: board = [
  [5,1,5],
  [1,1,1],
  [5,1,5]
]
Output: [[0,1],[1,0],[1,1],[1,2],[2,1]]

Row 1 and column 1 are both runs of three 1s. Tile [1,1] is in both matches and is listed once.