← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Google SWE interview with a string manipulation problem that looks deceptively simple but has a bunch of subtle invariants you need to nail down. The focus was heavily on proving correctness and complexity rather than just getting a working solution.

Questions Asked (1)

Q1

You have two equal-length strings made up of 'L', 'R', '.', and 'X' characters. 'L' tokens can slide left over empty slots but not right, not through walls, not through other tokens. 'R' tokens do the opposite. Can you transform the start string into the target string using valid moves? Design an O(n) time, O(1) space algorithm, explain your invariants, argue correctness, and walk through edge cases like mismatched walls, tokens separated by walls, and consecutive tokens with no room to move.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I spent way too long trying to think of something clever before realizing the key insight is pretty mechanical once you see it: strip out the dots and the relative order of L/R/X tokens must match exactly between start and target, and walls must be in identical positions.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and define the invariants: the sequence of non-wall characters must be identical in both strings, and each 'L' in the start must not be to the left of its corresponding 'L' in the target, while each 'R' must not be to the right. Then, design a single-pass algorithm that checks these conditions in O(n) time and O(1) space, and discuss edge cases and correctness.

Pro tip: Emphasize that the relative order of tokens is invariant because tokens cannot pass through each other or walls. This simplifies the problem to checking positions of corresponding tokens, which you can do in one pass without extra space.

1. Clarify rules and invariants

Restate the movement rules: 'L' moves left only, 'R' moves right only, cannot jump over walls or other tokens. Identify key invariants: the sequence of non-wall characters must match, and the relative order of tokens is preserved.

2. Check sequence equality

Verify that the strings of non-wall characters (ignoring '.') are identical. If not, transformation is impossible.

3. Validate token positions

For each corresponding 'L' in start and target, ensure start index >= target index (since 'L' can only move left). For each 'R', ensure start index <= target index (since 'R' can only move right).

4. Design O(n) time, O(1) space algorithm

Use two pointers to traverse both strings simultaneously, skipping '.', and check the conditions in a single pass without extra data structures.

5. Discuss edge cases and correctness

Cover cases like mismatched walls, tokens separated by walls, consecutive tokens with no room to move, and argue why the invariants guarantee feasibility.

Key Points to Mention

  • Invariant: The sequence of non-wall characters must be identical in start and target.
  • Invariant: 'L' tokens can only move left, so their start index must be >= target index; 'R' tokens can only move right, so start index <= target index.
  • Walls ('X') are fixed and cannot be moved; they partition the string into independent segments.
  • Tokens cannot pass through each other, so their relative order is preserved.
  • The algorithm can be implemented in one pass with two pointers, achieving O(n) time and O(1) space.
  • Edge cases: mismatched walls, tokens blocked by walls, consecutive tokens with no empty space, and strings with no tokens.

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