Katkat

Decide string transform with directional tokens and walls

GoogleSoftware Engineer · Technical Screen

Last updated

Decide string transform with directional tokens and walls evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

You are given two equal-length strings start and target of length n, each consisting only of the characters 'L', 'R', '.', and 'X'. A dot '.' represents an empty slot; 'X' represents an immovable wall; 'L' and 'R' are tokens that may move across empty slots subject to these rules: (

  1. An 'L' token may move any number of positions left into '.', but may never move right, pass through another token, or pass through an 'X'. (
  2. An 'R' token may move any number of positions right into '.', but may never move left, pass through another token, or pass through an 'X'. (
  3. Only one token can occupy a position at any time. Determine whether target can be obtained from start by a sequence of valid moves. If yes, return true; otherwise, return false. Design an algorithm that runs in O(n) time and O(
  4. extra space beyond a few pointers/counters. Explain your invariants, prove correctness informally, analyze time and space complexity, and walk through a few tricky edge cases (e.g., mismatched wall layouts, blocks separated by walls, consecutive tokens with no gaps).