Sort by

recency

|

393 Discussions

|

  • + 0 comments

    If solving for the case where {a,b} is the same as {b,a} as most people are doing to accunt for Test5 being wrong, why not use a Set as the key? Then no need to do this Key and InvertKey logic? That's in the spirit of using Sets as per the challenge! (even though, again, the challenge is not correct)

  • + 0 comments

    Resuelto

            Set<String> obj = new HashSet<>();
            
            for (int i = 0; i < t; i++) {
                
                String strKey = pair_left[i] +" "+ pair_right[i];
                String strInvertKey = pair_right[i] +" "+ pair_left[i];
                
                if(!obj.contains(strKey) && !obj.contains(strInvertKey)){
                    obj.add(strKey);
                }
                
                System.out.println(obj.size());
            }
            
    
  • + 0 comments

    Test case #5 conflicts with the requirement that the pair (a, b) should not be treated as the same as (b, a).

  • + 0 comments
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            
            Scanner scanner = new Scanner(System.in);
            
            Set<String> uNames = new HashSet<>();
            int count = scanner.nextInt();
            for (int ii = 0; ii < count; ii++) {
                String name1 = scanner.next();
                String name2 = scanner.next();
                // This is wrong in the problem statement for "Test case 5" where
                // (a,b) is the same as (b,a)
                // addressing this symmetry here
                if (!uNames.contains(name1.concat(" ").concat(name2))
                 && !uNames.contains(name2.concat(" ").concat(name1))) {
                    uNames.add(name1.concat(" ").concat(name2));    
                 }
                
                System.out.println(uNames.size());
            }
            
            scanner.close();
        }
    }
    
  • + 0 comments

    Test case #5 is incorrect tho

    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<AbstractMap.SimpleEntry<String, String>> set = new HashSet<>();
    
            for (int i = 0; i < t; i++) {
                
                set.add(new AbstractMap.SimpleEntry<>(pair_left[i], pair_right[i]));
                System.out.println(set.size());
            }
       }
    }