Ctrl K

Pattern With Gaps

Easy
You are given a string text and a pattern pattern made of lowercase English letters and at least one star *. Each star may be replaced with any string, including the empty one; different stars are replaced independently. Return True if the stars can be replaced so that the pattern turns into a contiguous piece of text, and False otherwise.
Example 1
text='blackboard', pattern='ac*oa' → True

Replace the star with "kb" to get "ackboa", which is a piece of the text.

Example 2
text='window', pattern='w*x' → False

The text has no "x", so no replacement can help.

Example 3
text='lemon', pattern='m*' → True

The star may become the empty string: "m" occurs in the text.

Constraints
  • 1 ≤ text.length ≤ 50
  • 1 ≤ pattern.length ≤ 50
  • text consists of lowercase English letters
  • pattern consists of lowercase English letters and contains at least one *
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWhere the Fragment Starts EasyWhole Copies of a Block EasyMatch After Shifts EasyWords Hidden in Others EasyFirst Word With a Given Beginning Easy
loading Python…
Input
text='blackboard', pattern='ac*oa'
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 212 tests on the server, hidden ones included.