The Occurrences After Bigram problem gives you a text string and two words first and second. Find all words that immediately follow the pair ("first", "second") in the text. This easy string problem tests clean word tokenization and sequential pattern matching.
Google asks this easy problem to verify string parsing and pattern matching skills — specifically, scanning for a two-word pattern and collecting the next word. The string interview pattern is demonstrated at its most fundamental.
Token scanning with pattern matching. Split the text into words. Scan with index i from 0 to n-3: if words[i] == first and words[i+1] == second, add words[i+2] to results. Return results.
text="alice is a good girl she is a good student", first="a", second="good". Words: ["alice","is","a","good","girl","she","is","a","good","student"].
Bigram pattern problems are straightforward sliding window problems on word arrays. Always split text into words first, then scan with a window of appropriate size (3 for bigram + next word). Handle the boundary carefully: stop at len(words) - window_size. Practice similar sliding window word pattern problems to build comfort with token-based scanning.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Count Asterisks | Easy | Solve | |
| Flip Game | Easy | Solve | |
| Generate a String With Characters That Have Odd Counts | Easy | Solve | |
| Goal Parser Interpretation | Easy | Solve | |
| License Key Formatting | Easy | Solve |