Java & C# Solution For HackerRank Problem: Compare the Triplets
Solving HackerRank Problem: Compare the Triplets using both java and C sharp
Problem
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....Complete the function compareTriplets in the editor below
...
See the full details of the problem Compare the Triplets
Solution
- Let Alice's triple score be a0,a1,a2.
- Let Bob's triple score be b0,b1,b2.
- Let Alice's and Bob's total rating points be ta and tb respectively. Set ta and tb to 0.
- If a0 > b0 then ta by 1.
- If b0 > a0 then tb by 1.
- If a1 > b1 then ta by 1.
- If b1 > a1 then tb by 1.
- If a2 > b2 then ta by 1.
- If b2 > a2 then tb by 1.
- Print ta and tb on console separated by space.
Time Complexity: O(1) //There are no iteration loops in the algorithm steps.
Space Complexity: O(1) //number of dynamically allocated variables remain constant for any input.
Credit: @github.com/RyanFehr
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.