Compare the Triplets

Sort by

recency

|

4289 Discussions

|

  • + 0 comments

    My rust solution

    fn compareTriplets(a: &[i32], b: &[i32]) -> Vec<i32> {
            a.iter().zip(b.iter()).fold(vec![0,0], |mut a, b| {
            if b.0 > b.1 {
                a[0] += 1;
            } else if b.0 < b.1 {
                a[1] += 1;
            }
            a
        })
    }
    
  • + 0 comments

    def compareTriplets(a, b): # Write your code here points =[0,0] for i, j in zip(a, b): if i > j: points[0] = points[0] + 1 elif i < j: points[1] = points[1] + 1 return points

  • + 0 comments

    This is how i solved this problem in java:

    public static List<Integer> compareTriplets(List<Integer> a, List<Integer> b) {
            int score_a=0;
            int score_b=0;
            List<Integer> score = new ArrayList<>();
            int size = Math.min(a.size(), b.size());
            for(int i=0; i<size; i++){
                if(a.get(i) > b.get(i)){
                    score_a += 1;
                }else if(a.get(i) < b.get(i)){
                    score_b += 1;
                }
            }
                score.add(score_a);
                score.add(score_b);
                return score;
        }
    
  • + 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;
    
    }
    
  • + 0 comments

    This is how I did it in python

    def compareTriplets(a, b):
        b_points = 0
        a_points = 0
        if len(a) != len(b):
            return
        for i in range(len(a)):
            if a[i] > b[i]:
                a_points += 1
            elif a[i] < b[i]:
                b_points += 1
            else:
                continue      
        return [a_points,b_points]