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:
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.
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
The first line contains an integer , the number of test cases.
Each of the test cases is represented as follows:
The first line contains two space-separated integers and , the number of rows in the search grid and the length of each row string.
This is followed by lines, each with a string of digits that represent the grid .
The following line contains two space-separated integers, and , the number of rows in the pattern grid and the length of each pattern row string.
This is followed by lines, each with a string of digits that represent the pattern grid .