CoinFlip
SRM 119 · 2002-11-07 · by axchma
Problem Statement
I advise them to use the following procedure, which makes the probability of either outcome equal: Flip the coin twice. If it flips heads the first time and tails the second time, then they watch "The Terminator"; if it flips tails the first time and heads the second time, then they watch "When Harry Met Sally". If it flips the same (heads or tails) both times, they repeat the procedure (they flip twice again).
Your task is, given a String representing the sequence of flip results, return the number of the flip (the flips are 1-indexed) after which they can choose a movie according to the protocol described above. If they can't choose return -1.
Constraints
- flips has between 0 and 50 characters inclusive
- each character of flips is either an 'H', representing heads, or a 'T', representing tails.
"" Returns: -1
"HHTH" Returns: 4
"TTHHTHHHTH" Returns: 6
"TTHH" Returns: -1
"TT" Returns: -1
Submissions are judged against all 44 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CoinFlip with a public method int decide(string flips) · 44 test cases · 2 s / 256 MB per case