The Find and Replace Pattern interview question asks you to filter a list of words to find those that match a given pattern. A word matches a pattern if there is a permutation of characters such that replacing every character in the pattern with its mapped character results in the word. This is essentially a check for isomorphism—the structure of the mapping must be one-to-one (bijective).
Amazon and Zomato use this problem to test your understanding of character mapping and the Hash Table interview pattern. It evaluation whether you can implement a two-way (bi-directional) mapping to ensure that two different characters in the pattern don't map to the same character in the word, and vice versa. It’s a test of logical consistency and efficient string processing.
This problem uses Bi-directional Mapping with two Hash Maps (or one map and a "seen" set).
pattern_to_word and word_to_pattern.Pattern: "abb", Word: "mee"
{a: m, m: a}.{a: m, m: a, b: e, e: b}.Pattern: "abb", Word: "xyz"
pattern can be transformed into word without checking if multiple pattern characters map to the same word character (e.g., "aba" mapping to "ccc").A great way to simplify isomorphism problems is to "normalize" the strings. Map the first unique character seen to 'a', the second to 'b', and so on. If the normalized versions of two strings are identical, the strings match the same pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Vowel Spellchecker | Medium | Solve | |
| Word Subsets | Medium | Solve | |
| Find Duplicate File in System | Medium | Solve | |
| Evaluate the Bracket Pairs of a String | Medium | Solve | |
| Group Shifted Strings | Medium | Solve |