Collect Coins With Tokens

Asked at Google

Reported by the problem's creator, not verified

A board is a string of cells. A . is an empty cell, a T holds a token, and a C holds a coin.

Implement max_coins.

Examples

  1. Example 1

    Input: board = T..C..C..

    Output: 2

    Explanation: The token moves from index 0 to 3 and collects that coin, then from 3 to 6 for the second one.

  2. Example 2

    Input: board = T.C...T.C

    Output: 0

    Explanation: The token at index 0 can only land on indices 0, 3 and 6, and the token at index 6 cannot move (index 9 is off the board). The coins at indices 2 and 8 sit on cells no token ever lands on.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.