← Questions

Most coins collected by tokens that jump three cells

0
GoogleCodingLast asked Feb 2026

A coding interview question asked in Google's HackerRank assessment, last asked Feb 2026. It tests greedy, strings and simulation.

A one-player board game is played on a string board of N cells. Each cell is empty (.), holds one of the player's tokens (T) or holds a coin (C). A move picks one token at index i and moves it exactly three cells to the right, to i + 3; the two cells in between do not matter. A token that lands on a coin collects it. Return the most coins the player can collect.

Interface

  • solution(board: str) -> int

Rules:

  • A move is allowed only if i + 3 < N and the destination does not hold another token.
  • A collected coin is removed; each coin counts once.
  • A token can be moved any number of times, and the player may have several tokens.

Example

"TT.T.CCCCC"  ->  3     # coins at 6, 7 and 9; nothing can reach 5 or 8
"T...CCCC"    ->  1     # only the coin at 6 is reachable from index 0
"C..TT.CT.C"  ->  2     # the token at 3 collects 6 and 9
"CT.C.TC.C"   ->  1     # only the coin at 8, from the token at 5

Constraints

  • 1 <= N <= 100
  • Every character is ., T or C.

Clarifying questions

  • Can a token jump over another token (only the landing cell is checked)?
  • Does a token have to stop when it reaches a coin, or can it keep moving?
  • Is there a limit on the number of moves?
  • Must the coins be collected by the same token, or by any?

What a strong answer covers

  • The key observation: a token only ever visits cells with the same index modulo 3, so the board splits into three independent lanes.
  • In a lane, every coin after the first token is collectable (the leading token can always keep advancing), and every coin before it is not.
  • An O(N) scan per lane, no search over move sequences.
  • Why blocking by another token never costs a coin, argued or checked against a brute force on small boards.

Follow-ups

  • Tokens may move 1, 2 or 3 cells. What changes?
  • Each move costs one point and each coin is worth v. Maximise the score.
  • Tokens can also move left.

Where it's asked

  • Google · HackerRank assessment · Last asked Feb 202690 min · Two problems on HackerRank · Some early-career assessments enable the built-in assistant; others forbid AI. The invitation says which.

What it tests

greedy · strings · simulation

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding