Regular Expression Matching
HardDynamic ProgrammingDynamic Programming
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given an input string s and a pattern p, implement regular expression matching with support for . and * where:
- . matches any single character.
- * matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Examples
Input: s = "aa", p = "a"
Output: false
"a" does not match the entire string "aa".
Input: s = "aa", p = "a*"
Output: true
"a*" means zero or more a's.
Input: s = "ab", p = ".*"
Output: true
".*" means zero or more of any character.
Constraints
- 1 <= s.length <= 20
- 1 <= p.length <= 20
- s contains only lowercase English letters.
- p contains only lowercase English letters, '.', and '*'.
- It is guaranteed for each occurrence of '*', there will be a previous valid character to match.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.