In the Evaluate the Bracket Pairs of a String coding problem, you are given a string that contains keys enclosed in parentheses, such as (name). You are also given a dictionary (or a 2D array of key-value pairs). Your task is to replace every occurrence of a bracketed key with its corresponding value from the dictionary. If a key is not found in the dictionary, replace it with a question mark ?.
Google uses this problem to test basic string parsing and Hash Table interview pattern skills. It evaluates how efficiently you can extract substrings and perform lookups. It's a practical task that mimics template engine logic (like how variables are replaced in HTML templates). It checks if you can avoid O(N^2) string operations by using efficient string building techniques.
The problem uses a One-pass String Parsing approach combined with a Hash Map.
(, start recording characters until you hit ).?) to a result buffer.String: hi (name), how is (place)?
Knowledge: {"name": "bob", "place": "paris"}
(: key is "name". Map has "bob". Append "bob".(: key is "place". Map has "paris". Append "paris".hi bob, how is paris?res += char in a loop in languages like Java or Python, which creates new string objects and results in O(N^2) time. Use a StringBuilder or a list of characters.Always mention the difference between immutable and mutable strings. Using a StringBuilder (Java) or "".join(list) (Python) is a signal of a senior-level understanding of performance.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| People Whose List of Favorite Companies Is Not a Subset of Another List | Medium | Solve | |
| Group Shifted Strings | Medium | Solve | |
| Word Subsets | Medium | Solve | |
| Find Duplicate File in System | Medium | Solve | |
| Find and Replace Pattern | Medium | Solve |