FastPrepWildcard Matching with Stars
Problem · String

Wildcard Matching with Stars

Learn this problem
MediumConfluent logoConfluentNEW GRADPHONE SCREEN

Problem statement

You are given a lowercase string text and a pattern pattern containing lowercase letters and the wildcard *.

A letter matches the same letter. A * matches any sequence of characters, including the empty sequence. Return true if the entire pattern matches the entire text; otherwise return false.

Consecutive stars have the same meaning as a single star.

Function

matchesPattern(text: String, pattern: String) → boolean

Examples

Example 1

text = "adceb"pattern = "*a*b"return = true

The first star can match the empty prefix and the second star can match dce.

Example 2

text = "acdcb"pattern = "a*c*d"return = false

The pattern requires a final d, but the text ends with b; no star expansion can change that literal mismatch.

Example 3

text = "abc"pattern = "***"return = true

Consecutive stars collectively match the entire text.

Constraints

  • 0 <= text.length <= 200000.
  • 1 <= pattern.length <= 200000.
  • text contains lowercase English letters.
  • pattern contains lowercase English letters and *.

More Confluent problems

drafts saved locally
public boolean matchesPattern(String text, String pattern) {
    // Write your code here.
}
text"adceb"
pattern"*a*b"
expectedtrue
checking account