Regular Expression Match Problem Statement
Given a string str
and a string pat
, where str
may contain wildcard characters '?' and '*'.
If a character is '?', it can be replaced with any single character. If a character is '*', it can be replaced with any sequence of characters (including an empty sequence).
Your task is to determine whether it is possible to transform str
such that it matches pat
using the given wildcard rules.
Input:
The first line of input contains an integer T
, representing the number of test cases.
The next 2 * T
lines represent the T
test cases.
The first line of each test case contains the string str
.
The second line of each test case contains the string pat
.
Output:
For each test case, return true
if it is possible to modify str
such that it matches pat
under the given rules; otherwise, return false
.
Example:
Input:
str = "abc?", pat = "abcd"
Output:
true
Explanation:
The '?' can be replaced with 'd', making str
and pat
identical.
Constraints:
1 <= T <= 10
1 <= pat.length() <= 200
1 <= str.length() <= 200
- Time Limit: 1 sec
Note:
You do not need to print anything; just implement the function. The strings do not contain whitespace. The string pat
contains only lowercase English alphabets.
Follow Up:
Try to solve this problem in O(M * N).

AnswerBot
4mo
The task is to determine if it is possible to transform a string to match another string using wildcard characters '?' and '*'.
Iterate through both strings simultaneously, handling wildcard characters...read more
Help your peers!
Add answer anonymously...
Oracle Member Technical Staff interview questions & answers
A Member Technical Staff was asked 2mo agoQ. Given a string, find all possible codes that the string can generate. You are gi...read more
A Member Technical Staff was asked 2mo agoQ. You are given the heads of two sorted linked lists list1 and list2. Merge the tw...read more
A Member Technical Staff was asked 3mo agoQ. How can you detect a loop in a linked list?
Popular interview questions of Member Technical Staff
A Member Technical Staff was asked 3mo agoQ1. Given a string, find all possible codes that the string can generate. You are gi...read more
A Member Technical Staff was asked 3mo agoQ2. You are given the heads of two sorted linked lists list1 and list2. Merge the tw...read more
A Member Technical Staff was asked 3mo agoQ3. How can you detect a loop in a linked list?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

