 GENE01 - Editorial

Setter: Srikkanth R
Tester: Aryan Choudhary
Editorialist: Ajit Sharma Kasturi

CAKEWALK

None

PROBLEM:

We are given two characters denoting the eye colors of two people in Chefland. The character R denotes Brown color, B denotes Blue color, and G denotes Green color. Green is the rarest of colors and Brown is the most common. The eye color of the child of two people is most likely to be the most common eye color between them. We need to determine the most likely eye color of the child of those two people given.

EXPLANATION:

• Actually to the given problem statement, the order of most likely color of the child is R \gt B \gt G.

• Therefore, if the two colors are R and B, we output R, if the two colors are B and G, we output B, if the two colors are G and R, we output R.

• In case of both the given characters in the input are same, we obviously output that character itself.

TIME COMPLEXITY:

O(1) for each testcase.

SOLUTION:

Editorialist's solution
#include <iostream>
using namespace std;

int main() {

char ch1, ch2;
cin >> ch1 >> ch2;

if ((ch1 == 'R' && ch2 == 'B') || (ch1 == 'B' && ch2 == 'R')) {
cout << 'R' << endl;
}
else if ((ch1 == 'B' && ch2 == 'G') || (ch1 == 'G' && ch2 == 'B')) {
cout << 'B' << endl;
}
else if ((ch1 == 'G' && ch2 == 'R') || (ch1 == 'R' && ch2 == 'G')) {
cout << 'R' << endl;
}
else {
cout << ch1 << endl;
}

return 0;
}

Setter's solution
a = input()

if a == "R R" or a == "R B" or a == "R G" or a == "B R" or a == "G R":
print("R")

elif a == "B B" or a == "B G" or a == "G B":
print("B")

elif a == "G G":
print("G")

Tester's solution
def main():
s=input()
for x in "RBG":
if x in s:
print(x)
break

main()

Please comment below if you have any questions, alternate solutions, or suggestions. where does my code fails? thank you in advance
#include
using namespace std;

int main() {
char a,b;
cin>>a>>b;
if(a==‘R’||b==‘R’)
{
cout<<‘R’<<endl;
}
else if(a==‘G’||b==‘G’)
{
cout<<‘G’<<endl;
}
else
{
cout<<‘B’<<endl;
}
return 0;
}

G B

Expected Output
B

G

Where is error in my code, I used NODE JS, thanks in advance.

process.stdin.resume();
process.stdin.setEncoding(‘utf8’);