Regular Expression Matching
Check if string s matches pattern p '.' matches any single character '*' matches zero or more of the preceding element Example: s = "aa", p = "a" => false (doesn't cover entire string) Example: s = "aa", p = "a*" => true ('*' means zero or more 'a') Example: s = "ab", p = ".*" => true ('.*' matches any string)
Regular Expression Matching is about turning repeated work into a reusable state instead of re-solving subproblems. It's a hard one for a reason: it stresses state-and-transition thinking when the rules pile up. Don't rush the code—spend your time nailing the state definition first.
Examples
You write
is_match(s: str, p: str)
Example 1
- Input
- s = "aa", p = "a"
- returns
- false
Example 2
- Input
- s = "aa", p = "a*"
- returns
- true
The pattern behind it
Strings
I reach for it when
- The input is text and the answer is a count, a substring or a new string.
- You need to compare, reverse or rebuild characters.
Say this before you type. Say which array pattern the string is hiding before you touch a character.
All 51 Strings problemsBacktracking
I reach for it when
- The question asks for all combinations, permutations or placements.
- You make a choice, explore it, and may need to take it back.
Say this before you type. Say the choice, the stopping rule, and the earliest moment you can prune.
All 15 Backtracking problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.
Prep guides that list this problem
Our company tags come from public interview write-ups. None of these is a confirmed question.