← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Google SWE interview with a string search problem that sounds straightforward until you actually have to think about cross-boundary matches. The question had more edge cases than I expected going in.

Questions Asked (1)

Q1

Given a list of strings, search for a target string by treating the list as a continuous flat character stream, where each character's position is tracked by its string index and character index. For example, searching for 'de' in ['a', 'bcd', 'ea', 'de'] should return [1, 2] because the 'd' starts at string 1, char 2, and the 'e' continues into string 2. Can matches span across consecutive strings? Implement an efficient solution.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The cross-boundary part is what got me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose an efficient algorithm that avoids concatenating all strings. Use a sliding window over the virtual concatenated string, tracking the current string and character indices, and handle matches that span across string boundaries.

Pro tip: Mention that you can achieve O(n) time and O(1) extra space by iterating through the strings and maintaining a rolling hash or using KMP, but be prepared to discuss trade-offs between simplicity and optimality.

1. Clarify requirements and edge cases

Ask about input size, character set, whether the target can be empty, and if overlapping matches should be returned. Confirm that matches can span across strings.

2. Choose an algorithm

Decide between a simple sliding window over concatenated strings (O(n*m) worst-case) or a more efficient string matching algorithm like KMP adapted for multiple strings (O(n+m)).

3. Design index mapping

Plan how to map positions in the virtual concatenated string back to (string index, character index) pairs, especially when a match spans multiple strings.

4. Implement and test

Write clean code with helper functions to get characters by virtual index, and test with cases including matches at boundaries, no match, and multiple matches.

5. Analyze complexity and trade-offs

Discuss time and space complexity of your solution, and compare with alternatives like concatenation or using a trie if multiple queries are expected.

Key Points to Mention

  • Handling matches that span across string boundaries by tracking both string and character indices.
  • Avoiding unnecessary concatenation to save memory, especially for large lists of strings.
  • Using efficient string matching algorithms like KMP or Rabin-Karp to achieve linear time complexity.
  • Edge cases: empty target, target longer than total characters, overlapping matches, and multiple matches.
  • Time and space complexity analysis: O(n) time with O(1) extra space for KMP, where n is total characters.
  • Potential follow-up: if multiple queries, preprocess the list into a single string or build an index.

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