Given an array of strings of digits, try to find the occurrence of a given pattern of digits. In the grid and pattern arrays, each string represents a row in the grid. For example, consider the following grid:
1 | 1234567890 |
The pattern array is:
1 | 876543 |
The pattern begins at the second row and the third column of the grid and continues in the following two rows. The pattern is said to be present in the grid. The return value should be YES
or NO
, depending on whether the pattern is found. In this case, return YES
.
Function Description
Complete the gridSearch function in the editor below. It should return YES
if the pattern exists in the grid, or NO
otherwise.
gridSearch has the following parameter(s):
- string G[R]: the grid to search
- string P[r]: the pattern to search for
Input Format
The first line contains an integer t
, the number of test cases.
Each of the t
test cases is represented as follows:
The first line contains two space-separated integers R
and C
, the number of rows in the search grid G
and the length of each row string.
This is followed by R
lines, each with a string of C
digits that represent the grid G
.
The following line contains two space-separated integers, r
and c
, the number of rows in the pattern grid P
and the length of each pattern row string.
This is followed by r
lines, each with a string of c
digits that represent the pattern grid P
.
Returns
- string: either
YES
orNO
Constraints
- 1 <= t <= 5
- 1 <= R, r, C, c <= 1000
- 0 <= r <= R
- 0 <= c <= C
Sample Input
1 | 2 |
Sample Output
1 | YES |
Explanation
The first test in the input file is:
1 | 10 10 |
The pattern is present in the larger grid as marked in bold below.
1 | 7283455864 |
The second test in the input file is:
1 | 15 15 |
The search pattern is:
1 | 99 |
This pattern is not found in the larger grid.
Solution
1 | /* |