Skip to content

Compare the triplets – Hackerrank Challenge – Java solution

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CompareTheTripletsHackerrank {

	static List<Integer> compareTriplets(List<Integer> a, List<Integer> b) {
		int aliceTotalScore = 0, bobTotalScore = 0;

		for (int i = 0; i < 3; i++) {
			int aliceScore = a.get(i);
			int bobScore = b.get(i);
			if (aliceScore != bobScore) {
				int temp = aliceScore > bobScore ? aliceTotalScore++ : bobTotalScore++;
			}

		}
		List<Integer> result = new ArrayList<>();
		result.add(aliceTotalScore);
		result.add(bobTotalScore);
		return result;
	}

}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.