GRAND ASSIGNMENT - 2 One Color
One Color
Given a string of length N, made up of only uppercase characters 'R' and 'G', where 'R' stands for Red and 'G' stands for Green. Find out the minimum number of characters you need to change to make the whole string of the same colour.
Input
The input will be a single line containing a string.
Output
The output should be single line containing the integer representing the minimum number of characters you need to change to make the whole string of the same colour.
Explanation
For example, if string is "GGGGGGR" . We need to change only the last character to 'G' to make the string same-coloured.then output is 1.
Input
The input will be a single line containing a string.
Output
The output should be single line containing the integer representing the minimum number of characters you need to change to make the whole string of the same colour.
Explanation
For example, if string is "GGGGGGR" . We need to change only the last character to 'G' to make the string same-coloured.then output is 1.
Sample Input 1Sample Output 1
GGGGGGR
1
Sample Input 2Sample Output 2
RGG
1
str=input()
r,g=0,0
for char in str:
if char =="R":
r+=1
else:
g+=1
print(min(r,g))
Comments
Post a Comment