Microsoft · Question 70 · Dynamic Programming
Regular Expression Matching
Problem
Implement regex matching with. (any char) and * (zero or more of previous char).
Approach
DP over both prefixes; '*' skips or consumes a matching char.
Time O(m×n)Space O(m×n)
How it works
- 1Empty pattern matches empty string (plus a* cases).
- 2'*' skips its char or consumes one matching char.
- 3Other positions need a direct or '.' match.
Sample input / output
Input: aa a* Output: true
Constraints
1 <= s, p lengths <= 20.
Solution — read it, then walk it
Time O(m×n)Space O(m×n)Loops 3Branches 4Returns 1source · Java
Scroll sideways for wide charts — the view follows the active step.
- start / end
- statement
- condition
- loop
- returns
- definition
1/23
StartSTART
Interactive control-flow diagram and step-by-step code walkthrough.
Recommended resourcesAffiliate links · may earn us a commission
Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits