How do you implement wildcard matching with '?' and '*'?
PICTURE THIS: 1, 2, 2, 8
Simple meaning
DP where dp[i][j] means s[:i] matches p[:j]
WHY — Strings instead of guessing?
Why interviewers care about Strings:
question about Strings.
trade-offs, and what you would actually do on a DSA project - not buzzwords.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1DP where dp[i][j] means
s[:i] matches p[:j]
- 2'?' copies the diagonal
and '*' is empty (dp[i][j-1]) or eat one more s char (dp[i-1][j]).
- 3How it works
Time and space are O(n*m)
- 4Give an example
you can roll two rows.
- 5Greedy two-pointer with star
rewind also works but is easier to get wrong.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
DP where dp[i][j] means s[:i] matches p[:j] '?' copies the diagonal and '*' is empty (dp[i][j-1]) or eat one more s char (dp[i-1][j]).