Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Regular Expression Matching

Hard

Topics
StringDynamic ProgrammingRecursion

Given a string s (first line) and a pattern p (second line) supporting . (any single char) and * (zero or more of the preceding element), return true if the pattern matches the entire string.

Example 1

Input:  s = "aa", p = "a*"
Output: true

Example 2

Input:  s = "ab", p = ".*"
Output: true

Example 3

Input:  s = "mississippi", p = "mis*is*p*."
Output: false

Constraints

  • 1 <= s.length <= 20
  • 1 <= p.length <= 20
  • Each * has a valid preceding element.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access