← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Google SWE coding round with a string manipulation problem that looks straightforward but has a few edge cases worth thinking through.

Questions Asked (1)

Q1

Given a string with patterns enclosed in percent signs and a dictionary mapping those patterns to replacement values, replace all patterns with their corresponding values. If any pattern is missing from the dictionary, return an error string instead.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was regex and I almost went that route before catching myself.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the exact pattern syntax and error handling expectations, then propose a single-pass scan using a stack or state machine to identify patterns and replace them. Discuss trade-offs between regex-based and manual parsing, and emphasize handling edge cases like nested or malformed patterns.

Pro tip: Mention that you would confirm whether patterns can be nested or contain percent signs, as this drastically changes the parsing strategy. Also, suggest returning a specific error message format to make debugging easier.

1. Clarify requirements and edge cases

Ask about pattern syntax (e.g., can patterns contain spaces, nested percent signs, or be empty?), error handling (return error string vs throw exception), and expected output format.

2. Choose parsing strategy

Decide between regex (simple but may fail on nested patterns) and manual scanning (more robust). Explain the trade-offs and pick one based on clarified requirements.

3. Implement replacement logic

Scan the string, identify patterns between percent signs, look them up in the dictionary, and build the result. If a pattern is missing, return the error string immediately.

4. Handle edge cases and errors

Address cases like unmatched percent signs, empty patterns, patterns with special characters, and multiple occurrences. Ensure error handling is consistent.

5. Analyze complexity and test

Discuss time and space complexity (O(n) time, O(n) space for output). Walk through test cases including normal, missing pattern, and malformed input.

Key Points to Mention

  • Pattern syntax and delimiters: how to identify start and end of a pattern, and whether escaping is needed.
  • Error handling strategy: return a specific error string vs throwing an exception, and when to fail fast.
  • Algorithm choice: single-pass scan with state (e.g., in_pattern flag) vs regex, and trade-offs.
  • Edge cases: empty patterns, unmatched percent signs, nested patterns, patterns containing percent signs.
  • Time and space complexity: O(n) time, O(n) space for output, and potential for in-place if mutable.
  • Testing approach: unit tests for normal replacement, missing pattern, malformed input, and performance with large strings.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.