Find a Symbolic Pattern in a Numeric Matrix
Problem statement
Slide pattern over every fitting position of matrix in row-major order. A pattern token is either an integer literal or one lowercase letter.
- An integer literal must equal the covered matrix value.
- Every occurrence of one letter must map to the same value.
- Different letters must map to different values.
Return the first matching top-left coordinate, or [-1,-1] when none exists.
Function
findSymbolicPattern(matrix: int[][], pattern: String[][]) → int[]Examples
Example 1
matrix = [[9,9,9,4,1],[9,9,9,1,8]]pattern = [["4","a"],["a","8"]]return = [0,3]The source-shaped pattern first matches at coordinate [0,3].
Example 2
matrix = [[1,2],[3,4]]pattern = [["9"]]return = [-1,-1]A missing literal returns the sentinel.
Constraints
1 <= matrix rows, columns <= 1001 <= pattern rows, columnsand the pattern fits inside the matrix.