ThreeProgrammers
2016 TCO Algo 1C · 2016-03-24 · by praveen123
Problem Statement
This problem is about three programmers who work together on a project. The programmers' names are Alice, Bob, and Charles. We will use 'A', 'B', and 'C' to denote them.
Each day exactly one of the three programmers works on the project. The code history is a string that specifies who worked on which day. For example, the string "AAC" means that Alice worked on the project for two days in a row and then Charles worked for a day.
Alice is always able to work on the project. Each time Bob spends a day working, he needs to take at least one day off before he is able to work again. Each time Charles spends a day working, he needs to take at least two days off.
The above information means that not all strings are valid code histories. For example, the string "BB" is not a valid code history because Bob cannot work two days in a row.
You are given a
Constraints
- code will contain between 1 and 50 characters, inclusive.
- Each character in code will be one of 'A', 'B', and 'C'.
"CAB" Returns: "BCA"
The input is a valid code history. In fact, any permutation of this input is a valid code history, and you may return any of them.
"CBB" Returns: "BCB"
Bob cannot work on two consecutive days. Hence, "BCB" is the only valid code history that is a permutation of the given input.
"BB" Returns: "impossible"
"BBA" Returns: "BAB"
"CAC" Returns: "impossible"
Submissions are judged against all 200 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ThreeProgrammers with a public method string validCodeHistory(string code) · 200 test cases · 2 s / 256 MB per case