#C405. Minimum Changes to Avoid Consecutive Red Lights
Minimum Changes to Avoid Consecutive Red Lights
Minimum Changes to Avoid Consecutive Red Lights
You are given a string s representing a sequence of traffic lights. Each character of s is either R
(red) or G
(green). A configuration is considered valid if there are no two consecutive red lights. In one change, you can change a red light to a green light. Your task is to compute the minimum number of changes needed to make the sequence valid.
In mathematical terms, for a given string s, for every index i such that:
you should increment the counter and skip the next light, as it has been effectively fixed. This method ensures that there are no two adjacent red lights left in the sequence.
inputFormat
The input consists of a single line containing a non-empty string s composed only of the characters 'R' and 'G'. The input is read from standard input (stdin).
outputFormat
Output a single integer representing the minimum number of changes required so that there are no two consecutive 'R' characters in the string. The output should be written to standard output (stdout).
## sampleGRGRG
0