← Google Interview Insights

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

IntermediatePrefer not to say
Jun 2026

Summary

Google SWE coding round, one problem about simulating piece movement on a 1D board. Pretty clean problem once you see the key insight, but I spent way too long trying to brute-force it before the right approach clicked.

Questions Asked (1)

Q1

Given two equal-length strings representing a 1D board with pieces 'R' (can only move right), 'L' (can only move left), and '_' (empty), determine if the start configuration can be transformed into the target configuration through valid moves.

Algorithms & Data Structures
Author's notes

My first instinct was to simulate moves which is obviously wrong at scale.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that pieces cannot jump over each other, so the relative order of R's and L's must be identical in both strings. Then, verify that each R in the start is at or to the left of its corresponding R in the target, and each L is at or to the right of its corresponding L, ignoring underscores.

Pro tip: Mention that this is a linear-time O(n) solution with O(1) extra space, and emphasize that the key insight is that pieces cannot pass through each other, which simplifies the problem to checking relative order and directional constraints.

1. Clarify movement constraints

Confirm that pieces can only move into adjacent empty spaces and cannot jump over other pieces. This means the relative order of pieces is preserved.

2. Check relative order

Extract the sequence of R's and L's from both strings (ignoring underscores) and verify they are identical. If not, return false.

3. Verify directional constraints

Iterate through both strings simultaneously, and for each R in start, ensure its index is <= the index of the corresponding R in target. For each L, ensure its index is >= the index of the corresponding L in target.

4. Return result

If all checks pass, return true; otherwise, return false.

Key Points to Mention

  • Relative order of pieces is invariant because pieces cannot jump over each other.
  • R can only move right, so its start index must be <= target index.
  • L can only move left, so its start index must be >= target index.
  • Underscores represent empty spaces and can be ignored when comparing piece sequences.
  • Time complexity is O(n) and space complexity is O(1) if done in a single pass.
  • Edge cases: strings of length 1, no pieces, or all pieces already in correct positions.

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