Compare the Triplets

Sort by

recency

|

4371 Discussions

|

  • + 0 comments
           Iterator<Integer> it1 = a.iterator();
           Iterator<Integer> it2 = b.iterator();
           int count1 = 0, count2 = 0;
           while(it1.hasNext() && it2.hasNext()) {
            int i = it1.next();
            int j = it2.next();
            if(i>j) {
                count1 = count1 + 1;
            } else if(i < j) {
                count2 = count2 +1;
            }
           }
           return Arrays.asList(count1, count2);
            
        }
    
    }
    
  • + 0 comments
    import java.io.*;
    import java.math.*;
    import java.security.*;
    import java.text.*;
    import java.util.*;
    import java.util.concurrent.*;
    import java.util.function.*;
    import java.util.regex.*;
    import java.util.stream.*;
    import static java.util.stream.Collectors.joining;
    import static java.util.stream.Collectors.toList;
    
    
    
    public class Solution {
        public static void main(String[] args){
            Scanner sc=new Scanner(System.in);
            int[] a=new int[3];
            int[] b=new int[3];
            for(int i=0;i<3;i++){
                a[i]=sc.nextInt();
            }
            for(int i=0;i<3;i++){
                b[i]=sc.nextInt();
            }
            int c1=0,c2=0;
            for(int i=0;i<3;i++){
                for(int j=0;j<3;j++){
                    if(i==j){
                        if(a[i]>b[j]){
                            c1++;
                        }
                        if(a[i]<b[j]){
                            c2++;
                        }
                    }
                }
            }
            System.out.println(c1+" "+c2);
        }
    }
    
  • + 0 comments

    Great explanation of the algorithm! I’ve always been interested in understanding algorithm efficiency, especially when working with real-world data. I’m also working on a project where I use efficient data structures to categorize and sort menu pricing data. If anyone is interested in fast lookup operations, you can check out my project here: https://mcdonaldmenuprices.com/

  • + 1 comment

    Here's my solution in Python 3: (Any improvements are welcome)

    def compareTriplets(a, b):
        # Write your code here
        A=B=0
        for i in range(3):
            if a[i]>b[i]: A+=1
            elif a[i]<b[i]: B+=1
        a.append(A)
        b.append(B)
        return a[3], b[3]
    
  • + 0 comments

    public static List compareTriplets(List a, List b) { List result=new ArrayList<>(); int sum=0; int sum1=0; int sum2=0; int sum3=0; for(int i=0;ib.get(i)){ sum1=sum1+1; result.add(sum1); }
    else if(a.get(i)b.get(j)){ sum2= sum2+1; result.add(sum2); } else if(a.get(j)