← Google Interview Insights

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

Intermediate
Jul 2026

Summary

Google SWE coding round, one algorithmic problem about tokens moving on a 1D board. Pretty niche constraint (exactly 3 steps right) that pushed it away from obvious DP patterns at first glance.

Questions Asked (1)

Q1

Given a 1D board represented as a string with tokens and coins, each token can only move exactly 3 steps to the right per move. A token collects a coin if it lands on one. Find the maximum number of coins collectable across all tokens with optimal movement.

Algorithms & Data Structures
Author's notes

The 'exactly 3 steps' constraint is the whole puzzle.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a maximum weight matching or dynamic programming problem where each token can move to positions i+3k and collect coins. Use DP to compute the maximum coins for each token independently, then combine using a greedy or DP approach if tokens can overlap. Clarify constraints and edge cases before coding.

Pro tip: Discuss the time and space complexity trade-offs and mention that if tokens are indistinguishable, the problem reduces to selecting disjoint positions; if distinguishable, use DP with bitmask or flow. Also, handle the case where a token cannot move (no valid positions) gracefully.

1. Clarify problem constraints

Ask about board size, number of tokens, whether tokens can occupy the same cell, and if coins are removed after collection. This determines the algorithm's complexity.

2. Model as graph or DP

Represent each token's possible moves as a directed acyclic graph (positions i, i+3, i+6, ...). The problem becomes finding a maximum weight set of paths or matching.

3. Solve for independent tokens

If tokens don't interfere, compute max coins per token via DP: dp[i] = max coins from position i to end. Then sum over tokens.

4. Handle token interactions

If tokens compete for coins, use DP with state (token index, position) or reduce to maximum weight matching in a bipartite graph (tokens vs coin positions).

5. Analyze complexity and optimize

Discuss time/space complexity and possible optimizations like greedy if coins are sparse or using min-cost max-flow for general case.

Key Points to Mention

  • Dynamic programming recurrence for a single token: dp[i] = coin[i] + max(dp[i+3], dp[i+6], ...)
  • Greedy approach may fail; need DP or matching for optimality
  • If tokens are identical, problem reduces to selecting maximum number of non-overlapping coins with step 3
  • Use of memoization or bottom-up DP to avoid recomputation
  • Edge cases: no coins, tokens at end, multiple tokens on same cell
  • Complexity: O(n * m) for DP where n is board length and m is number of tokens, or O(n^3) for matching

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