How do you implement regular-expression matching for '.' and '*'?
PICTURE THIS: A SENTENCE BECOMES TOKENS
The model does not read letters like humans. It reads these pieces, then predicts the next one.
Simple meaning
DP on prefixes: '*' means zero copies of the previous token (skip two pattern chars) or one more match of the previous token if it fits.
WHY — DP instead of guessing?
Why interviewers care about DP:
question about DP.
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 with tokens?
Before the model can read a sentence, it goes through these steps:
- 1DP on prefixes: '*'
means zero copies of the previous token (skip two pattern chars) or one more match of the previous token if it fits.
- 2Token IDs
'.' matches any one character.
- 3Embeddings
Time and space are O(n*m).
- 4Recursion with memo is
the same recurrence
- 5Next token
greedy star eating is incorrect.
- 6Decode
IDs turn back into readable text.
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 on prefixes: '*' means zero copies of the previous token (skip two pattern chars) or one more match of the previous token if it fits. '.' matches any one character.