Compare the Triplets

  • + 0 comments

    This is how I solve this problem in java:

    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;
    
    }