AAlgoLab
ALG-H014HardDynamic Programming

Full Pattern Matcher

Return whether pattern matches the entire text. A dot matches any one character; * means zero or more repetitions of the immediately preceding pattern token. All other lowercase letters match literally.

Contract

input text: string
input pattern: string
return boolean

Constraints

  • • Pattern is valid: * never appears first or after another *
  • • Text and literal pattern letters are lowercase a-z

Examples

Example 1
text = "aab"
pattern = "c*a*b"
→ true
Example 2
text = "aa"
pattern = "a"
→ false

5 judge tests (2 shown above). Target complexity: O(text_length * pattern_length).