Wildcard Matching with Stars
Updated
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) → booleanExamples
Example 1
text = "adceb"pattern = "*a*b"return = trueThe first star can match the empty prefix and the second star can match dce.
Example 2
text = "acdcb"pattern = "a*c*d"return = falseThe 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 = trueConsecutive stars collectively match the entire text.
Constraints
0 <= text.length <= 200000.1 <= pattern.length <= 200000.textcontains lowercase English letters.patterncontains lowercase English letters and*.
More Confluent Phone Screen questions
- Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Match a Variadic Function SignaturePHONE SCREEN · Seen Oct 2026
- Sequential Phrase Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Time Map with Sum and AveragePHONE SCREEN · Seen Sep 2026
- Time-Based Key-Value Store with Range AggregatesPHONE SCREEN · Seen Sep 2026
- Word Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Windowed Key-Value MapPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
- Least-Strong Common DefeaterPHONE SCREEN · Seen Oct 2022
Similar questions at other companies
- Shortest Way to Form a Target StringPinterest · PHONE SCREENPinterest interview questions
- Text Pattern Matching with StarsHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Palindrome After At Most One DeletionAdobe · PHONE SCREENAdobe interview questions
- Minimum Swaps to Make PalindromeAmazon · OA
- Smallest Merge of Two StringsCapital One · OACapital One interview questions
- Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
- Missing WordsVanguard · OAVanguard interview questions
- Longest Palindromic SubstringSiemens · PHONE SCREEN
- Reverse Words in a StringAgoda · PHONE SCREENAgoda interview questions
- Longest Palindromic SubstringIBM · PHONE SCREENIBM interview questions