Created
June 29, 2024 10:19
-
-
Save samarthsewlani/421d3d45f80e54d05e146837f9809297 to your computer and use it in GitHub Desktop.
Compare Triplets HackerRank Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.hackerrank.com/contests/cp-24-25-batch-coding-fundamentals-classwork/challenges/compare-the-triplets/problem | |
import java.util.*; | |
public class Solution { | |
public static void main(String args[]){ | |
Scanner sc = new Scanner(System.in); | |
// Step 1: Take inputs | |
int n = 3; | |
int alice[] = new int[n], bob[] = new int[n]; | |
for(int i=0;i<n;i++) alice[i] = sc.nextInt(); | |
for(int i=0;i<n;i++) bob[i] = sc.nextInt(); | |
// Step 2: initialise DS if needed | |
// Step 3: Main logic/processing | |
int aliceScore = 0, bobScore = 0; | |
for(int i=0;i<n;i++){ | |
int a = alice[i], b = bob[i]; | |
if(a>b){ | |
aliceScore++; | |
} | |
else if(b>a){ | |
bobScore++; | |
} | |
} | |
// Step 4: Output | |
System.out.println(aliceScore + " " + bobScore); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment