HackerRank Compare The Triplets solution

Hello Programmers, In this post, you will learn how to solve HackerRank Compare The Triplets solution. This problem is a part of the HackerRank Algorithms Series.

One more thing to add, don’t straight away look for the solutions, first try to solve the problems by yourself. If you find any difficulty after trying several times, then look for the solutions. We are going to solve the HackerRank Algorithms problems using C, CPP, JAVA, PYTHON, JavaScript & SCALA Programming Languages.

You can practice and submit all HackerRank problem solutions in one place. Find a solution for other domains and Sub-domain. I.e. Hacker Rank solution for HackerRank C ProgrammingHackerRank C++ ProgrammingHackerRank Java Programming, HackerRank Python ProgrammingHackerRank Linux ShellHackerRank SQL Programming, and HackerRank 10 days of Javascript.

HackerRank Compare The Triplets solution
HackerRank Compare The Triplets solution

As you already know that this site does not contain only the Hacker Rank solutions here, you can also find the solution for other problems. I.e. Web Technology, Data StructuresRDBMS ProgramsJava Programs Solutions,  Fiverr Skills Test answersGoogle Course AnswersLinkedin Assessment, and Coursera Quiz Answers.

HackerRank Compare The Triplets


Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty.

The rating for Alice’s challenge is the triplet a = (a[0], a[1], a[2]), and the rating for Bob’s challenge is the triplet b = (b[0], b[1], b[2]).

The task is to find their comparison points by comparing a[0] with b[0]a[1] with b[1], and a[2] with b[2].

  • If a[i] > b[i], then Alice is awarded 1 point.
  • If a[i] < b[i], then Bob is awarded 1 point.
  • If a[i] = b[i], then neither person receives a point.

Comparison points is the total points a person earned.

Given a and b, determine their respective comparison points.


a = [1, 2, 3]
b = [3, 2, 1]

  • For elements *0*, Bob is awarded a point because a[0] .
  • For the equal elements a[1] and b[1], no points are earned.
  • Finally, for elements 2a[2] > b[2] so Alice receives a point.

The return array is [1, 1] with Alices score first and Bob’s second.

Function Description

Complete the function compareTriplets in the editor below.

compareTriplets has the following parameter(s):

  • int a[3]: Alice’s challenge rating
  • int b[3]: Bob’s challenge rating


  • int[2]: Alice’s score is in the first position, and Bob’s score is in the second.

Input Format

The first line contains 3 space-separated integers, a[0]a[1], and a[2], the respective values in triplet a.
The second line contains 3 space-separated integers, b[0]b[1], and b[2], the respective values in triplet b.


  • 1 ≤ a[i] ≤ 100
  • 1 ≤ b[i] ≤ 100

Sample Input 0

5 6 7
3 6 10

Sample Output 0

1 1

Explanation 0

In this example:

  • a = (a[0], a[1], a[2]) = (5, 6, 7)
  • b = (b[0], b[1], b[2]) = (3, 6, 10)

Now, let’s compare each individual score:

  • a[0] > b[0], so Alice receives 1 point.
  • a[1] = b[1], so nobody receives a point.
  • a[2] < b[2], so Bob receives 1 point.

Alice’s comparison score is 1, and Bob’s comparison score is 1. Thus, we return the array [1, 1].

Sample Input 1

17 28 30
99 16 8

Sample Output 1

2 1

Explanation 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].

HackerRank Compare The Triplets solution

HackerRank Compare The Triplets solution in C

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int a0; 
    int a1; 
    int a2; 
    scanf("%d %d %d",&a0,&a1,&a2);
    int b0; 
    int b1; 
    int b2; 
    scanf("%d %d %d",&b0,&b1,&b2);
    int a,b;
    else if(b0>a0)
    else if(b1>a1)
    else if(b2>a2)
        printf("%d %d",a,b);
    return 0;

HackerRank Compare The Triplets solution in Cpp

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <set>
#include <map>
#include <complex>
#include <iostream>
#include <time.h>
#include <stack>
#include <stdlib.h>
#include <memory.h>
#include <bitset>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <vector>

using namespace std;

const int MaxN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
//  freopen("input.txt", "r", stdin);
  int a[3], b[3];
  for (int i = 0; i < 3; ++i) {
    cin >> a[i];
  int c1 = 0, c2 = 0;
  for (int i = 0; i < 3; ++i) {
    cin >> b[i];
    if (a[i] > b[i]) c1++;
    else if (a[i] < b[i]) c2++;
  cout << c1 << ' ' << c2 << endl;
  return 0;

HackerRank Compare The Triplets solution in Java

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a0 = in.nextInt();
        int a1 = in.nextInt();
        int a2 = in.nextInt();
        int b0 = in.nextInt();
        int b1 = in.nextInt();
        int b2 = in.nextInt();
        int a = 0;
        int b = 0;
        if (a0 > b0) a++;
        if (a0 < b0) b++;
        if (a1 > b1) a++;
        if (a1 < b1) b++;
        if (a2 > b2) a++;
        if (a2 < b2) b++;
        System.out.println(a + " " + b);

HackerRank Compare The Triplets solution in Python


import sys

a0,a1,a2 = raw_input().strip().split(' ')
A = a0,a1,a2 = [int(a0),int(a1),int(a2)]
b0,b1,b2 = raw_input().strip().split(' ')
B = b0,b1,b2 = [int(b0),int(b1),int(b2)]
alice = bob = 0
for x,y in zip(A,B):
    if x>y: alice += 1
    if x<y: bob += 1
print alice,bob

HackerRank Compare The Triplets solution using JavaScript


var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");

function readLine() {
    return input_stdin_array[input_currentline++];

/////////////// ignore above this line ////////////////////

function main() {
    var a0_temp = readLine().split(' ');
    var a0 = parseInt(a0_temp[0]);
    var a1 = parseInt(a0_temp[1]);
    var a2 = parseInt(a0_temp[2]);
    var b0_temp = readLine().split(' ');
    var b0 = parseInt(b0_temp[0]);
    var b1 = parseInt(b0_temp[1]);
    var b2 = parseInt(b0_temp[2]);
    var scoreA = 0;
    var scoreB = 0;
    if(a0 > b0) scoreA++;
    if(a0 < b0) scoreB++;
    if(a1 > b1) scoreA++;
    if(a1 < b1) scoreB++;
    if(a2 > b2) scoreA++;
    if(a2 < b2) scoreB++;

    console.log(scoreA + " " + scoreB);

HackerRank Compare The Triplets solution in Scala

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val total = lines.next().split(" ").map(_.toInt).zip(lines.next().split(" ").map(_.toInt)).fold((0,0)){ case (acc, pair) =>
    if(pair._1 > pair._2)
      (acc._1+1, acc._2)
    else if(pair._1 < pair._2)
      (acc._1, acc._2+1)
  println(s"${total._1} ${total._2}")

HackerRank Compare The Triplets solution in Pascal

ses math;
var  i,res,res1:longint; a,b:array[0..1000  ] of longint;
  for i:=1 to 3 do
   for i:=1 to 3 do

   for i:=1 to 3 do
   if a[i]>b[i] then inc(res) else
   if a[i]<b[i] then inc(res1);
   writeln(res,' ',res1);

Disclaimer: This problem (Compare The Triplets) is generated by HackerRank but the solution is provided by Chase2learn. This tutorial is only for Educational and Learning purposes.


1. How do you solve the first question in HackerRank?

If you want to solve the first question of Hackerrank then you have to decide which programing language you want to practice i.e C programming, Cpp Programing, or Java programming then you have to start with the first program HELLO WORLD.

2. How do I find my HackerRank ID?

You will receive an email from HackerRank to confirm your access to the ID. Once you have confirmed your email, the entry will show up as verified on the settings page. You will also have an option to “Make primary”. Click on that option. Read more

3. Does HackerRank detect cheating?

yes, HackerRank uses a powerful tool to detect plagiarism in the candidates’ submitted code. The Test report of a candidate highlights any plagiarized portions in the submitted code and helps evaluators to verify the integrity of answers provided in the Test.

4. Does HackerRank use camera?

No for coding practice Hackerrank does not use camera but for companies’ interviews code submission time Hackerrank uses the camera.

5. Should I put HackerRank certificate on resume?

These certificates are useless, and you should not put them on your resume. The experience you gained from getting them is not useless. Use it to build a portfolio, and link to it on your resume. 

6. Can I retake HackerRank test?

The company which sent you the HackerRank Test invite owns your Test submissions and results. It’s their discretion to permit a reattempt for a particular Test. If you wish to retake the test, we recommend that you contact the concerned recruiter who invited you to the Test and request a re-invite. 

7. What is HackerRank?

HackerRank is a tech company that focuses on competitive programming challenges for both consumers and businesses. Developers compete by writing programs according to provided specifications. Wikipedi

Finally, we are now, in the end, I just want to conclude some important message for you

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Please share our posts on social media platforms and also suggest to your friends to Join Our Groups. Don’t forget to subscribe. 

Sharing Is Caring

Leave a Comment