Answer to Question #205312 in Python for Jeevansai Gandham

Question #205312

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.

1
Expert's answer
2021-06-11T22:33:25-0400
s = input()
g = "G"
r = "R"
c_g = 0
c_r = 0
for ch in s:
	if ch == g:
		c_g += 1
	elif ch == r:
		c_r += 1
if c_g <= c_r:
	print(c_g)
else:
	print(c_r)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS