← Google Interview Insights

Google·Software Engineer·Online Assessment (OA)·Junior

JuniorPrefer not to say
May 2026Remote

Summary

Google early career SWE online assessment, two problems in 90 minutes. The one that stuck with me was a 1D board coin collection problem that looked deceptively simple but had enough edge cases to trip you up if you weren't careful about how tokens interact.

Questions Asked (1)

Q1

You're given a 1D string board with empty cells, player tokens, and coins. Each move slides any token exactly 3 cells to the right, and a coin is collected only when a token lands on it (not by passing through). Tokens can't occupy the same cell. Find the maximum number of coins collectable.

Algorithms & Data Structures
Author's notes

My first instinct was to simulate everything with BFS and I wasted probably 15 minutes going down that path before realizing the residue classes mod 3 basically partition the problem into independent subproblems.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a dynamic programming problem where the state is the positions of all tokens, and transitions correspond to sliding one token exactly 3 cells to the right if the destination is empty. Since the board is 1D and moves are uniform, we can process cells from left to right and use DP to maximize collected coins, ensuring no two tokens occupy the same cell. Discuss the state representation, transition, and optimization to handle large boards.

Pro tip: Clarify that coins are collected only when a token lands on them, not by passing through, and emphasize that tokens cannot share a cell. This shows attention to detail and avoids off-by-one errors in the DP transitions.

1. Clarify rules and constraints

Confirm the board size, number of tokens, and that moves are exactly 3 cells right, landing on a coin collects it, and tokens cannot overlap. Ask about edge cases like tokens at the right edge or coins at the start.

2. Define state and DP recurrence

Represent the state as the positions of all tokens (or a bitmask if small) and the current cell index. Define dp[i][mask] as the max coins collectable from cell i onward given token positions. Transition by either skipping a cell or moving a token from i to i+3 if empty and collecting coin if present.

3. Optimize state representation

If the number of tokens is large, note that tokens are indistinguishable and only their relative positions matter. Use a sliding window or greedy approach if possible, or reduce state by processing left to right and maintaining only relevant token positions.

4. Handle base cases and complexity

Base case: when no more moves possible, return 0. Analyze time and space complexity: O(n * 2^k) if using bitmask for k tokens, which may be exponential; discuss potential optimizations like greedy or interval scheduling if applicable.

5. Test with examples and edge cases

Walk through a small example to verify the DP, e.g., board 'T..C..' with one token. Test cases with multiple tokens, coins at positions 0, blocked moves, and tokens at the end.

Key Points to Mention

  • Dynamic programming with state as token positions and current index
  • Moves are exactly 3 cells right, landing on coin collects it
  • Tokens cannot occupy the same cell, so transitions must check emptiness
  • Coins are not collected by passing through, only by landing
  • State space can be reduced by noting tokens are indistinguishable
  • Time complexity and potential optimizations for large boards

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