FastPrepWildcard Pattern Matching
Problems/Wildcard Pattern Matching

Wildcard Pattern Matching

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a live online round for a Microsoft summer software intern role that the candidate applied to in Beijing. It was the first of two coding questions. The post says little beyond the topic, checking a string against a pattern. It also hints that the interviewer wanted a recursive solution.

It never defines the pattern symbols and gives no example or limits. Here we use the common wildcard rules. A ? stands for one character. A * stands for any run of characters, including none. The whole string must be covered. Both strings are up to 1000 characters. The text uses lowercase letters only. The pattern uses lowercase letters, ? and *. These rules and limits are our own choices.

Our version is about 50% the same as the reported question.

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) → boolean

Examples

Example 1

s = "microsoft"p = "m*o?oft"return = true

m 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 = false

The 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 = true

Each * can match an empty run of letters, so the empty string matches **.

Constraints

  • 0 <= s.length <= 1000
  • 0 <= p.length <= 1000
  • s contains only lowercase English letters.
  • p contains 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

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public boolean isMatch(String s, String p) {
        // Write your code here.
    }
}
Checking account…