Compare the Triplets
Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from to for three categories: , , and .
The rating for Alice's challenge is the triplet , and the rating for Bob's challenge is the triplet .
The task is to find their by comparing with , with , and with .
If , then Alice is awarded point.
If , then Bob is awarded point.
If , then neither person receives a point.
Comparison points is the total points a person earned.
Given and , determine their respective comparison points.
For elements *0*, Bob is awarded a point because
: Alice's score is in the first position, and Bob's score is in the second.
The first line contains
The second line contains space-separated integers, , , and , the respective values in triplet . space-separated integers, , , and , the respective values in triplet .
In this example:
a = (a, a, a) = (5,6,7)
b= (b,b,b) = (3,6,10)
Now, let's compare each individual score:
a>b, so Alice receives point.
a=b, so nobody receives a point.
a[2<b, so Bob receives point.
Alice's comparison score is 1, and Bob's comparison score is 1. Thus, we return the array [1,1].
Comparing the 0th elements, 17 < 99 so Bob receives a point.
Comparing the 1st and 2nd elements, 28 > 16 and 30 > 8 so Alice receives two points.
The return array is [2,1].
🔍Logic to follow to come-up with the solution :
1. Declare the required sets of variables to use.
2. Take the input number one by one.
3. Declare two variables and initialize them to zero ( i.e., int a=0, b=0; )
4. Now Compare the one variable with the other if the condition follow that is if 1st value of a1 is greater than b1 then increment the a (so, alice recieve one point) or if 1st value of a1 is smaller than b1 then increment b (so, bob recieve one point).
5. Similarly follow the same condition for other variables i.e., a2, b2, a3, b3.
6. Finally print the incremented values of a and b.
👨💻Let’s write the required code for the problem :
Sample Test Cases have been passed successfully
If you liked this post, then share this with your friends and if anything is confusing or incorrect then let me know in the comment section.
Thanks from my side, this is Mayank, keep learning and exploring !!