Sort by

recency

|

354 Discussions

|

  • + 0 comments

    I've looked through several solutions and I'm quite surprised. If the problem involves handling pairs and they're already split into two arrays, why combine them back into a single string? Instead, there's a more elegant approach using the SimpleEntry class. You can simply use

    Set<AbstractMap.SimpleEntry<String, String>> uniquePairs = new HashSet<>();

    to handle the pairs directly.

  • + 0 comments

    hi guys i think converting the both arrays into string and adding it into a set is much easy process

    import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution {

    public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); String [] pair_left = new String[t]; String [] pair_right = new String[t];

        for (int i = 0; i < t; i++) {
            pair_left[i] = s.next();
            pair_right[i] = s.next();
        }
        Set<String> nameSet = new HashSet<>();
        for(int i =0; i<t; i++){
            String str = pair_left[i]+" "+pair_right[i];
            nameSet.add(str);
            System.out.println(nameSet.size());
        }
    }
    

    }

  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        sc.nextLine();
        Set<String> set=new HashSet<>();
        for(int i=0;i<n;i++){
            String str1=sc.nextLine();
            set.add(str1);
           System.out.println(set.size());  
        }
    
        sc.close();
    }
    

    }

  • + 0 comments
        Set<String> set=new LinkedHashSet<>();
        String x;
    
         for(int i=0;i<pair_left.length;i++){
             x="";
             x=pair_left[i]+" "+pair_right[i];
             set.add(x);
             System.out.println(set.size());
         }
    
  • + 0 comments
    HashSet<String> hs = new HashSet<>();
    for (int i = 0; i < t; i++) {
        hs.add(pair_left[i]+","+pair_right[i]);
        System.out.println(hs.size());
    }