← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
Jun 2026

Summary

Google SWE coding round with a pattern matching problem that looks straightforward until you actually think about the wildcard semantics. The example tripped me up more than I expected.

Questions Asked (1)

Q1

Design a rules engine that maps binary input strings to configuration values using a pattern list, where patterns can contain '0', '1', '.', and '*' (wildcard matching any length of binary sequence). Implement a match function that finds the correct pattern for a given binary input and returns its associated value.

Algorithms & Data StructuresSystem Design
Author's notes

The example input was patterns ('1*0', 5) and ('*10', 10) with input '110', expected output 10.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify requirements first: pattern semantics (e.g., '.' matches exactly one bit, '*' matches any sequence including empty), precedence when multiple patterns match, and expected scale. Then design a solution that balances simplicity and efficiency, such as a trie with wildcard handling or dynamic programming, and discuss trade-offs.

Pro tip: Proactively discuss how to handle overlapping patterns and define deterministic precedence (e.g., longest match or pattern order) to avoid ambiguity, and mention that '*' can be optimized by precomputing transitions or using memoization to avoid exponential blowup.

1. Clarify requirements and constraints

Ask about pattern semantics, input size, number of patterns, and expected performance. Confirm how conflicts are resolved (e.g., first match, longest match, or priority).

2. Choose a matching strategy

Decide between a trie-based approach for efficiency or dynamic programming for simplicity. Consider that '*' introduces non-determinism, so a trie may need to branch or use backtracking.

3. Design the data structures

If using a trie, each node represents a bit (0 or 1) and may have special edges for '.' and '*'. For DP, define a state (pattern index, input index) and transitions.

4. Implement the match function

Write pseudocode for the matching algorithm, handling '.' as a single-bit wildcard and '*' as a multi-bit wildcard. Ensure correct handling of empty matches and backtracking.

5. Analyze complexity and optimize

Discuss time and space complexity. For DP, it's O(P * N) where P is pattern length and N is input length. For trie, it can be O(N * branching factor) but may degrade with many '*'. Suggest optimizations like memoization or precomputation.

Key Points to Mention

  • Pattern semantics: '.' matches exactly one bit, '*' matches zero or more bits.
  • Handling overlapping patterns: define deterministic precedence (e.g., longest match, pattern order).
  • Algorithm choices: dynamic programming vs. trie with wildcard support.
  • Complexity analysis: time and space for both approaches.
  • Edge cases: empty input, patterns with only '*', multiple '*' in a pattern.
  • Scalability: how to handle large pattern sets (e.g., indexing, caching).

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