The "Before and After Puzzle interview question" is a string concatenation challenge. You are given a list of phrases. A "puzzle" is formed by merging two phrases, and , if the last word of phrase is exactly the same as the first word of phrase . The resulting phrase should contain the shared word only once. You need to find all unique merged phrases and return them in lexicographical (alphabetical) order.
Companies like Clutter use the "Before and After Puzzle coding problem" to test a candidate's ability to handle string parsing, hash maps, and sorting. It evaluates whether you can efficiently find pairs that satisfy a condition without using a nested loop that might be too slow for larger datasets. It's a test of "Hash Table interview pattern" and "String interview pattern."
This problem is best solved using a Hash Map for Prefix/Suffix indexing.
Set to store the merged phrases to handle duplicates.Phrases: ["writing code", "code is fun", "fun times"]
["code is fun times", "writing code is fun"].When searching for pairs that share a common key, always use a Hash Map. It turns a search into an lookup. Practice splitting strings by space and re-joining them—these are foundational "String interview pattern" skills.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Alert Using Same Key-Card Three or More Times in a One Hour Period | Medium | Solve | |
| Find And Replace in String | Medium | Solve | |
| Group Anagrams | Medium | Solve | |
| Groups of Special-Equivalent Strings | Medium | Solve | |
| High-Access Employees | Medium | Solve |