-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRed_OR_Green.cpp
42 lines (39 loc) · 863 Bytes
/
Red_OR_Green.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Link:- https://practice.geeksforgeeks.org/problems/red-or-green5711/1
Problem:- Find out the minimum number of characters you need to change to make the whole string of the same colour.
Input:
N=5
S="RGRGR"
Output:
2
Explanation:
We need to change only the 2nd and
4th(1-index based) characters to 'R',
so that the whole string becomes
the same colour.
Input:
N=7
S="GGGGGGR"
Output:
1
Explanation:
We need to change only the last
character to 'G' to make the string
same-coloured.
*/
int RedOrGreen(int n,string s) {
//code here
int count1=0,count2=0;
for(int i=0;i<n;i++)
{
if(s[i]=='R')
{
count1++;
}
else
{
count2++;
}
}
return min(count1,count2);
}