Maximize coins collected by tokens jumping +3
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Interview Round: Take-home Project
Quick Answer: 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.
Input: "C..TT.CT.C"
Expected Output: 2
Explanation: The collectable coins are at indices 6 and 9. They share a lane with the token at index 3. No other coin has a token before it in the same lane.
Input: "CCCC"
Expected Output: 0
Explanation: There are no tokens, so no coin can be collected.
Input: "T"
Expected Output: 0
Explanation: A single token with no space to move and no coins to collect.
Input: "TCTCTC"
Expected Output: 2
Explanation: The coins at indices 3 and 5 are in lanes that already have tokens before them. The coin at index 1 is not collectable because there is no earlier token in its lane.
Input: "CCTCCTTCCC"
Expected Output: 2
Explanation: Only the coins at indices 8 and 9 have a token earlier in the same modulo-3 lane. All other coins are before the first token in their lane or in a lane with no token.
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.