Compare the Triplets

  • + 0 comments

    My Java solution with o(n) time complexity and o(1) space complexity:

    public static List<Integer> compareTriplets(List<Integer> a, List<Integer> b) {
            int aliceScore = 0, bobScore = 0;
            //iterate over each val
            for(int i = 0; i < a.size(); i++){
                int alicePts = a.get(i);
                int bobPts = b.get(i);
                
                //if a[i] > b[i], increase alice points
                if(alicePts > bobPts) aliceScore++;
                //if a[i] < b[i], increase bob points
                else if(alicePts < bobPts) bobScore++;
            }
            
            //return list of alice and bobs points
            return Arrays.asList(aliceScore, bobScore);
        }