Wildcard Pattern Matching
Updated
Problem statement
You are given a string s and a pattern p. Return true if the pattern matches the whole string, and false otherwise.
The pattern can use two special characters:
'?'matches exactly one letter, whatever it is.'*'matches any run of letters, including an empty run.
Every other character in p is a letter and matches only that same letter. Matching only part of s is not enough: the pattern has to account for every letter of s, from the first to the last.
Function
isMatch(s: String, p: String) → booleanExamples
Example 1
s = "microsoft"p = "m*o?oft"return = truem matches m. The * takes icr. Then o matches o, ? takes the single letter s, and oft matches the last three letters. The whole string is used, so the answer is true.
Example 2
s = "intern"p = "*t?r"return = falseThe pattern ends with r, so the last letter of s must be r. The last letter of intern is n, so there is no match.
Example 3
s = ""p = "**"return = trueEach * can match an empty run of letters, so the empty string matches **.
Constraints
0 <= s.length <= 10000 <= p.length <= 1000scontains only lowercase English letters.pcontains only lowercase English letters,'?'and'*'.
More Microsoft Onsite Interview questions
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
- Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Scramble StringExpedia · ONSITE INTERVIEWExpedia interview questions
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Edit DistanceAstrotalk · PHONE SCREEN
- Minimum Dictionary SegmentsGoogle · PHONE SCREENGoogle interview questions
- Maximum Crayon Removal ScoreWells Fargo · OAWells Fargo interview questions
- Shuffle a String by Swapping Tree ChildrenNutanix · OANutanix interview questions
- Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
- Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
- Maximum Bouquet ValueOracle · ONSITE INTERVIEWOracle interview questions