← Google Interview Insights

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

IntermediatePrefer not to say
May 2026

Summary

Google SWE coding round with a string matching problem that looked deceptively simple but had some tricky edge cases to think through.

Questions Asked (1)

Q1

Given a dictionary of words and a 'jammed' input string (where any character in a word may be repeated consecutively any number of times), return all dictionary words that could have produced the jammed string.

Algorithms & Data Structures
Author's notes

My first instinct was to just regex it, like collapse consecutive duplicate characters in the jammed string and compare.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the jammed string is formed by repeating characters in the original word, so each character in the word appears at least once consecutively. For each dictionary word, check if it can match the jammed string by using a two-pointer technique: advance through both strings, ensuring that each character in the word matches the corresponding character in the jammed string and that the jammed string has at least one occurrence of that character. If the entire word is consumed and the jammed string is also fully consumed, the word is a valid candidate.

Pro tip: Mention that you can optimize by grouping dictionary words by their unique character sequence (e.g., 'hello' -> 'helo') to avoid redundant checks, and pre-filter words whose length exceeds the jammed string length.

1. Clarify the problem

Confirm that the jammed string is formed by repeating characters in the original word, and that the original word must have each character appearing at least once consecutively. Ask if the dictionary can contain duplicates or if the output should be unique.

2. Design the matching algorithm

For each word, use two pointers: one for the word and one for the jammed string. While both pointers are within bounds, if characters match, advance both; if not, return false. After the word is exhausted, ensure the jammed pointer has also reached the end.

3. Optimize with pre-processing

Group dictionary words by their compressed form (consecutive duplicates removed) to quickly skip words that cannot match. Also, filter out words longer than the jammed string.

4. Handle edge cases

Consider empty dictionary, empty jammed string, words with all same characters, and words that are prefixes of the jammed string but not complete matches.

5. Analyze complexity

Time complexity: O(N * L) where N is number of words and L is average word length, but with grouping it can be improved. Space complexity: O(N) for storing results and groups.

Key Points to Mention

  • Two-pointer technique for matching the word against the jammed string
  • Compressing words by removing consecutive duplicates to group and optimize
  • Ensuring the jammed string is fully consumed when the word ends
  • Handling cases where a character in the word does not match the jammed string
  • Time and space complexity analysis
  • Edge cases: empty input, single-character words, words with repeated characters

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