We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static List<Integer> compareTriplets(List<Integer> a, List<Integer> b) {
if(a.size() != b.size()){
throw new IllegalArgumentException("Both lists size are not same!");
}
List<Integer> result = new ArrayList<>();
int bob = 0;
int alice = 0;
int size = Math.min(a.size(), b.size());
for(int i = 0; i < size; i++) {
if(a.get(i) > b.get(i)){
System.out.println("Alice recieve a point");
alice+= 1;
}
else if(a.get(i) < b.get(i)){
System.out.println("Bob recieves a point");
bob+=1;
}
else if(a.get(i).equals(b.get(i))){
System.out.println("Neither Bob or Alice recieve a point");
}
}
result.add(alice);
result.add(bob);
return result;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Compare the Triplets
You are viewing a single comment's thread. Return to all comments →
This is how I solve this problem in java: