You are given a 1D board represented by a string s of length n (1 <= n <= 100). Each character is one of:
-
'.'
: empty cell
-
'C'
: a cell containing one coin
-
'T'
: a cell containing a token (there may be multiple tokens)
Movement rules:
-
Each token may be moved any number of times.
-
A move for a token is
exactly
3 cells to the right: from index
i
to index
i + 3
.
-
Moves to the left or by any other distance are not allowed.
-
A move is
invalid
if the destination cell is currently occupied by another token.
-
Coins:
-
If a token
lands
on a cell containing a coin, the coin is collected.
-
Each coin can be collected at most once total (after it is collected, it disappears).
-
Coins that a token “jumps over” during a move are
not
collected (only the destination cell matters).
Task: Compute the maximum number of coins the player can collect by choosing an optimal sequence of token moves.
Output: an integer, the maximum collectible coins.
Notes/clarifications:
-
Tokens are considered distinct only in that they cannot occupy the same cell at the same time.
-
You may assume all input tokens/coins are initially placed according to
s
.
-
Tokens never leave the board; moves that would go past the end are not allowed.