FastPrepMatch a Pattern With ? and *
Problems/Match a Pattern With ? and *

Match a Pattern With ? and *

Adobe logoAdobe● HardFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem decides whether a pattern, where ? stands for any one letter and * for any run of letters (even none), matches a whole lowercase string. An Adobe SDE2 entry on Taro (a Glassdoor copy) names it as the second of two coding questions in its first technical round; the name is all it gives.

Our choices: lowercase letters only, both strings from 0 to 1000 characters, the pattern must cover the whole string, and new examples.

The judged task matches the report at about 90%.

You are given a string s and a pattern p. In the pattern:

  • a letter matches that same letter,
  • ? matches exactly one letter, any letter,
  • * matches any run of letters, including no letters at all.

Return true if the pattern matches the whole string s, and false otherwise.

Function

isWildcardMatch(s: String, p: String) → boolean

Examples

Example 1

s = "banana"p = "b*n?"return = true

b matches the first letter, * takes "ana", n matches the fifth letter and ? takes the last a: true.

Example 2

s = "cat"p = "c?t?"return = false

Without stars the pattern matches exactly 4 characters, but "cat" has 3: false.

Example 3

s = ""p = "**"return = true

Each * may match nothing, so two stars match the empty string: true.

Constraints

  • 0 <= s.length, p.length <= 1000
  • s contains only lowercase English letters
  • p contains only lowercase English letters, '?' and '*'

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public boolean isWildcardMatch(String s, String p) {
    // Write your code here.
}
Checking account…