GuidewireOA #1
Minimum Boys Next to Girls
Estimated MediumJudge-ready
Place the minimum number of boys in empty seats so that every girl has at least one directly adjacent seat occupied by a boy.
This site's standard input/output format and additional bounds are as described in this problem.
Input
One line containing a string s (1≤|s|≤2×10^5) consisting only of G and -.
Output
Output the minimum number of boys; output -1 if it is impossible.
Example 1
Input:
-G-GG--
Output:
2
Example 2
Input:
G-G
Output:
1
Example 3
Input:
G
Output:
-1
Editorial
Loading solution…