Maximum Coins With Moving Tokens
Learn this problemProblem statement
You are given a string board representing a row of cells. Each cell may contain a token 'T', a coin 'C', or be empty '.'.
In one move, the player may move one token exactly three positions to the right. If the token moves onto a coin, that coin is collected. A token cannot be moved if there is already another token in the position it would move onto.
What is the maximum number of coins the player can collect?
Write a function solution(board) that, given a string board of length N, returns the maximum number of coins the player can collect.
Source note: The screenshot is missing part of the question, but the examples are clear enough for practice. If you know the full original version, feel free to tell us; we'll update it when we find a clearer source. 🦤
Function
solution(board: String) → intExamples
Example 1
board = "TT.T.CCCCC"return = 3The player can move the third and second tokens twice, collecting three coins in total:
"TT.T.CCCCC" -> "TT...CTCCC" -> "TT...C.CCT" -> "T...TC.CCT" -> "T....C.TCT".
It is still possible to move the first token, but it cannot collect any coins.
Example 2
board = "T...CCCC"return = 1Example 3
board = "C..TT.CT.C"return = 2Constraints
Nis an integer within the range[1..100].- String
boardconsists only of the characters'.','T'and/or'C'.
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026