Compare the Triplets - HackerRank Problem Solving

Featured image

Compare the Triplets is an easy-level Python problem that requires basic knowledge of Python. In this post, we will provide a Python solution for Compare the Triplets.

Problem Statement and Explanation

Alice and Bob each submitted a problem to HackerRank. A reviewer evaluated the challenges on three categories - problem clarity, originality, and difficulty - using a scale of 1 to 100.

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

Comparison points are the total points a person earned.

Given a and b, determine their respective comparison points.

Input Format

Output Format

Compare the Triplets Solution in Python

Explanation of Solution in Python

The function called compareTriplets() that takes two lists as input, a and b. The function compares the corresponding elements of a and b and keeps a running tally of the number of times each person scores a point. The function then returns a list with the scores for Alice and Bob.

Compare the Triplets Solution in C++

Explanation of Solution in C++

The function first declares two variables, aliceScore and bobScore, to keep track of the scores for Alice and Bob. Then, it loops through the elements of the two lists, comparing the corresponding elements. If the element in a is greater than the corresponding element in b, then aliceScore is incremented. Otherwise, bobScore is incremented.

After the loop, the function pushes the scores for Alice and Bob onto a vector and then returns the vector.