Wildcard Matching
Updated
Problem statement
You are given a string s and a pattern p. Return true if the pattern matches the whole of s, and false otherwise.
Read the pattern like this:
- A letter matches the same letter.
?matches exactly one letter, any letter.*matches any run of letters, including an empty run.
The match must cover all of s, not just part of it.
Function
isMatch(s: String, p: String) → booleanExamples
Example 1
s = "tripjack"p = "trip*"return = truetrip matches the first four letters, and the star matches jack.
Example 2
s = "cab"p = "?a"return = falseThe pattern has no star, so it matches exactly two letters. s has three letters, so it cannot match.
Example 3
s = "abcde"p = "a*c?e"return = truea matches a. The star matches b. Then c matches c, ? matches d, and e matches e.
Example 4
s = ""p = "**"return = trueBoth stars match an empty run, so the pattern matches the empty string.
Constraints
0 <= s.length <= 20000 <= p.length <= 2000scontains only lowercase English letters.pcontains only lowercase English letters,?and*.
More Tripjack Onsite Interview questions
Similar questions at other companies
- Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
- Get Minimum ErrorsAmazon · OA
- Match a Pattern With ? and *Adobe · PHONE SCREENAdobe interview questions
- Most Relevant Text SpanHebbia · PHONE SCREEN
- Maximize Beautiful SubstringsFortinet · OAFortinet interview questions
- Minimum Taps to Water a GardenThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
- Interleaving StringsCARS24 · ONSITE INTERVIEW
- Text JustificationGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Greedy and Beam Sentence DecodingMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- Minimum Stickers to Form a Target StringByteDance · ONSITE INTERVIEWByteDance interview questions