461. Match Alphanumerical Pattern in Matrix I
Given a 2D integer matrix board and a 2D character matrix pattern. In the board, each element is an integer between 0 and 9. Each element of the pattern is either a digit or a lowercase English letter.
The task is to find a submatrix of board that matches pattern. An integer matrix part matches pattern if:
- The matrices have identical dimensions.
- If pattern[r][c] is a digit, then part[r][c] must be the same digit.
- If pattern[r][c] is a letter x, for every pattern[i][j] == x, part[i][j] must be the same as part[r][c] and for every pattern[i][j] != x, part[i][j] must differ from part[r][c].
Return an array [row, col] indicating the upper-left corner of the matched submatrix. If multiple matches exist, return the one with the lowest row index, and if still tied, the lowest column index. If no matches, return [-1, -1].
Example 1:
Input: board = [[1, 3, 3], [3, 3, 2], [2, 2, 2]]Â ,pattern = [['a','b'], ['b','b']]Â Â
Output: [0, 0]
Explanation:
If we map 'a' to 1 and 'b' to 3, the submatrix starting at (0,0) matches the pattern.
Example 2:
Input: board = [[5, 5, 6], [4, 7, 7], [1, 1, 8]], pattern = [['a','b'], ['7',7']]Â Â
Output: [0, 1]
Explanation:
Mapping '6' to 4 and 'a' to 5 gives a match at (0,1).
Now Your Turn!
Pick the correct output for the given inputInput: board = [[2, 3], [3, 2]], pattern = [['m'], ['m']]Â Â
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= board.length, board[i].length <= 50
- 0 <= board[i][j] <= 9
- 1 <= pattern.length, pattern[i].length <= 50
- pattern[i][j] is a digit or a lowercase English letter.