← Google Interview Insights

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

IntermediatePrefer not to say
May 2026

Summary

Google SWE coding round with a board simulation problem. Not the hardest thing I've seen but the constraints trip you up if you're not careful.

Questions Asked (1)

Q1

You have a 1D board with positions that are either empty, a token, or a coin. Tokens move exactly 3 steps right per move, collect a coin on landing, and can't share a position with another token. What's the maximum number of coins you can collect?

Algorithms & Data Structures
Author's notes

Took me a minute to even parse what was being asked.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a dynamic programming or greedy problem where tokens move exactly 3 steps right, collect coins on landing, and cannot share positions. Consider the parity of positions and the constraint that tokens cannot overlap, which may require tracking the rightmost token or using a DP state that captures the last occupied position. Aim to maximize coins by deciding which tokens to move and when, possibly using a DP over positions with states representing the number of tokens placed so far.

Pro tip: Clarify the initial configuration and whether tokens can move multiple times; if tokens can move repeatedly, the problem may reduce to selecting a set of non-overlapping landing positions spaced by multiples of 3. Also, consider edge cases like no tokens or no coins.

1. Understand the problem

Restate the rules: tokens move exactly 3 steps right, collect a coin on landing, cannot share a position. Ask clarifying questions about initial setup, number of tokens, and whether tokens can move multiple times.

2. Identify constraints and invariants

Note that each move changes a token's position by +3, so the parity of a token's position modulo 3 remains invariant. Also, tokens cannot occupy the same position, so their landing positions must be distinct.

3. Formulate as an optimization problem

Model as selecting a set of landing positions for tokens such that each is reachable by a sequence of +3 moves from its start, no two tokens land on the same position, and the total coins collected is maximized.

4. Design an algorithm

Use dynamic programming over positions, where dp[i] represents the maximum coins collectible considering positions up to i. Transition by either skipping a position or placing a token to land at i if it's a coin and reachable from a start token without conflict.

5. Analyze complexity and edge cases

Discuss time and space complexity (likely O(n) or O(n^2) depending on state). Consider edge cases: no tokens, no coins, tokens already at coins, and overlapping paths.

Key Points to Mention

  • Parity/invariant: token positions modulo 3 remain constant.
  • Non-overlapping constraint: tokens cannot share a position, so landing positions must be distinct.
  • Dynamic programming state: typically dp[i] = max coins up to position i, with transitions considering placing a token at i.
  • Greedy vs DP: greedy may fail due to conflicts; DP ensures optimality.
  • Reachability: a token can only land on positions congruent to its start modulo 3 and at least 3 steps away.
  • Edge cases: no tokens, no coins, tokens already on coins, and multiple tokens competing for the same coin.

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