You are given a 2D integer matrix board and a 2D character matrix pattern. Where 0 <= board[r][c] <= 9 and each element of pattern is either a digit or a lowercase English letter.
Your task is to find a submatrix of board that matches pattern. An integer matrix part matches pattern if we can replace cells containing letters in pattern with some digits (each distinct letter with a unique digit) in such a way that the resulting matrix becomes identical to the integer matrix part.
In other words:
- The matrices have identical dimensions
- If
pattern[r][c]is a digit, thenpart[r][c]must be the same digit - If
pattern[r][c]is a letterx:- For every
pattern[i][j] == x,part[i][j]must be the same aspart[r][c] - For every
pattern[i][j] != x,part[i][j]must be different thanpart[r][c]
- For every
Return an array of length 2 containing the row number and column number of the upper-left corner of a submatrix of board which matches pattern. If there is more than one such submatrix, return the coordinates of the submatrix with the lowest row index, and in case there is still a tie, return the coordinates of the submatrix with the lowest column index.
If there are no suitable answers, return [-1, -1].
Input & Output
Constraints
- 1 ≤ board.length, board[i].length ≤ 1000
- 1 ≤ pattern.length, pattern[i].length ≤ 100
- 0 ≤ board[i][j] ≤ 9
- pattern[i][j] is either a digit or a lowercase English letter