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
Given a string with wildcard characters, determine if it can be transformed to match another string under given rules.
Iterate through both strings simultaneously, handling wildcard characters '?' and ...read more
Help your peers!
Add answer anonymously...
Goldman Sachs Software Developer Intern interview questions & answers
A Software Developer Intern was asked 5mo agoQ. Write the code for Merge Sort.
A Software Developer Intern was asked Q. Rectangle Area Problem Statement You are provided with a list of rectangles, eac...read more
A Software Developer Intern was asked Q. First Non-Repeating Character Problem Statement You are given a string consistin...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked 6mo agoQ1. Write the code for Merge Sort.
A Software Developer Intern was asked Q2. Rectangle Area Problem Statement You are provided with a list of rectangles, eac...read more
A Software Developer Intern was asked Q3. First Non-Repeating Character Problem Statement You are given a string consistin...read more
>
Goldman Sachs Software Developer Intern Interview Questions
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

