Tap here to switch tabs
Problem
Submissions

Problem: Match Alphanumerical Pattern in Matrix I

med
30 min
Try to solve the Match Alphanumerical Pattern in Matrix I problem.

Statement

You are given a 2D2 D integer matrix board of size m×nm \times n and a 2D2 D character matrix pattern represented as an array of strings of size r×cr \times c.

A submatrix of board of size r×cr \times c with its top left corner at [i, j] matches pattern if there exists a valid mapping such that:

  • Each digit character in pattern matches the exact same integer value in the corresponding cell of board.

  • Each lowercase English letter in pattern maps to a single integer between 00 and 99.

  • Each letter maps to a unique integer (no two distinct letters map to the same integer).

  • Every occurrence of the same letter in pattern maps to the same integer in the submatrix.

Return an integer array of length 22 containing the row and column indices [i, j] of the top left corner of the matching submatrix. If multiple matches exist, return the one that appears first in row major order (smallest row index, and smallest column index in case of ties). If no match exists, return [-1, -1].

Constraints:

  • 1≤1 \leq board.length ≤50\leq 50

  • 1≤1 \leq board[i].length ≤50\leq 50

  • 0≤0 \leq board[i][j] ≤9\leq 9

  • 1≤1 \leq pattern.length ≤50\leq 50

  • 1≤1 \leq pattern[i].length ≤50\leq 50

  • pattern[i][j] is either a digit represented as a string or a lowercase English letter.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Match Alphanumerical Pattern in Matrix I

med
30 min
Try to solve the Match Alphanumerical Pattern in Matrix I problem.

Statement

You are given a 2D2 D integer matrix board of size m×nm \times n and a 2D2 D character matrix pattern represented as an array of strings of size r×cr \times c.

A submatrix of board of size r×cr \times c with its top left corner at [i, j] matches pattern if there exists a valid mapping such that:

  • Each digit character in pattern matches the exact same integer value in the corresponding cell of board.

  • Each lowercase English letter in pattern maps to a single integer between 00 and 99.

  • Each letter maps to a unique integer (no two distinct letters map to the same integer).

  • Every occurrence of the same letter in pattern maps to the same integer in the submatrix.

Return an integer array of length 22 containing the row and column indices [i, j] of the top left corner of the matching submatrix. If multiple matches exist, return the one that appears first in row major order (smallest row index, and smallest column index in case of ties). If no match exists, return [-1, -1].

Constraints:

  • 1≤1 \leq board.length ≤50\leq 50

  • 1≤1 \leq board[i].length ≤50\leq 50

  • 0≤0 \leq board[i][j] ≤9\leq 9

  • 1≤1 \leq pattern.length ≤50\leq 50

  • 1≤1 \leq pattern[i].length ≤50\leq 50

  • pattern[i][j] is either a digit represented as a string or a lowercase English letter.