Maximize coins collected by tokens jumping +3
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: Evaluates algorithmic reasoning about constrained discrete moves and optimization, focusing on state-space modeling, reachability under move constraints, and resource-maximization techniques.
Constraints
- 1 <= len(board) <= 100
- Each character of `board` is one of '.', 'T', or 'C'
Examples
Input: "TT.T.CCCCC"
Expected Output: 3
Explanation: Split by indices modulo 3. Coins at indices 6, 7, and 9 each have a token earlier in the same lane, so they can be collected. Coins at 5 and 8 cannot.
Input: "T...CCCC"
Expected Output: 1
Explanation: Only the coin at index 6 is in the same modulo-3 lane as the token at index 0. The other coins are unreachable.
Hints
- A token that starts at index `i` can only ever visit positions with the same value of `index % 3`.
- For each modulo-3 lane, think about which coins are impossible to reach and which ones will definitely be visited once there is at least one token before them.