


‘?’ – matches any single character
‘*’ – Matches any sequence of characters(sequence can be of length 0 or more)
The first line contains an Integer 'T' which denotes the number of test cases/queries to be run.
Then the test cases follow.
The first line of input for each test case/query contains a string representing the wildcard pattern.
The second line of input for each test case/query contains a string representing the text.
For each test case, print ‘True’ if the text matches the pattern, print ‘False’ otherwise(without quotes).
Output for every test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the function.
1 <= T <= 100
1 <= N <= 200
1 <= M <= 200
Where 'N' denotes the length of 'TEXT' and 'M' denotes the length of 'PATTERN'.
'TEXT' and 'PATTERN' contain only lowercase letters and patterns may contain special characters ‘*’ and ‘?’
Time Limit: 1sec
We will try to explore all the possibilities using the recursion.
Let’s say we have a recursive function ‘REC’ who has two arguments IDX and IDY where IDX represents the index in the text string and IDY represents the index in pattern string and its return type is boolean. Initially, we will call the rec with IDX = N and IDY = M where N is the size of the text string and M is the size of the pattern string.
We have taken care of the base cases now we need recursive relation to explore the cases. Create a variable RET = 0 to store the answer.
Let’s say we have a recursive function ‘REC’ who has two arguments IDX and IDY where IDX represents the index in the text string and IDY represents the index in pattern string and its return type is boolean. Initially, we will call the rec with IDX = n and IDY = m where n is the size of the text string and m is the size of the pattern string. We will have an N*M size matrix ‘DP’ to do the memoization.
We have taken care of the base cases now we need recursive relation to explore the cases. Create a variable RET = 0 to store the answer.
Store the value of ret at DP[IDX][IDY] that is memoized this state
And then return the RET.
Let’s define DP[i][j] as DP[i][j is true if first i characters in given text matches the first j characters of pattern.
Create a N*M dimensional array DP where N is the size of the text and M is the size of the pattern string.
Let’s take care of base cases first.
Now run two loop first from i = 1 to i = N and second loop from j = 1 to j = M and we will use same recursive relation here i.e
Now our answer is at DP[N][M] so return the value at DP[N][M].