GirlsAndBoys
TCO10 Qual 1 · 2010-04-11 · by soul-net
Problem Statement
You are given the current arrangement as a
Constraints
- row will contain between 1 and 50 characters, inclusive.
- Each character in row will be 'G' or 'B'.
Statement by TopCoder, Inc. — view the original on the archive.
"GGBBG" Returns: 2
You can swap the rightmost girl with the two boys (one after the other) to get "GGGBB", with a minimum of only 1 pair of adjacent students of different gender.
"BBBBGGGG" Returns: 0
There is already a single pair of adjacent students of different gender, and there is no arrangement without such pairs at all, so the best solution is to swap nothing.
"BGBGBGBGGGBBGBGBGG" Returns: 33
"B" Returns: 0
With only one student, there is not much swapping to do.
"G" Returns: 0
Submissions are judged against all 77 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GirlsAndBoys with a public method int sortThem(string row) · 77 test cases · 2 s / 256 MB per case