Timer is Running

Wildcard Pattern Matching
Submissions: 13529   Accuracy:

43.9%

  Difficulty: Medium   Marks: 4

Given a text 'str' and a wildcard pattern 'pattern', your task is to complete the function wildcard that returns '1' if the wildcard pattern is matched with text else returns '0'.The function takes two strings as arguments 'pattern' and 'str'.

The wildcard pattern can include the characters ‘?’ and ‘*’
‘?’ – matches any single character
‘*’ – Matches any sequence of characters (including the empty sequence)

For example,

Text = "baaabab",
Pattern = “*****ba*****ab", output : true
Pattern = "baaa?ab", output : true
Pattern = "ba*a?", output : true
Pattern = "a*ab", output : false 


Note: The matching should cover the entire text (not partial text).

Input:
The first line of input will contain no of test cases T. Then T test cases follow. Each test case contains 2 lines. The first line of each test case represents a string pat denoting the pattern and the next line contains string str.
Output:
The output will be 1 if the string follows the pattern else it will be 0.

Your Task:
Complete the function wildCard() which takes the two strings 'pattern' and 'str' as input parameters and returns the answer.

Expected Time Complexity: O(N*M)
Expected Auxiliary Space: O(N*M)

Constraints:
1 <= T <= 50
1 <= length of(str,pat) <= 200

Example
Input

2
a*a
aa
a?a
aa

Output
1
0

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal, Harshit Sidhwa
Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.