• + 0 comments

    I think the solution has an error. In set theory, the elements are unordered, i.e. John and Anne are the same pair as Anne and John. According to test case 2, e.g. cases: kg ni and ni kg are two different pairs. In my solution, in test 2 I have 975 different pairs, in their solution there are 990.

    If you find an error, let me know. My solution:

    import java.util.HashSet; import java.util.Scanner;

    public class SetOfSets { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);

        HashSet<String> names;
        String name1;
        String name2;
    
    
        HashSet<HashSet> setOfpairsOfnames = new HashSet<>();
        int N = scanner.nextInt();
        for (int i = 0; i < N; i++) {
            names = new HashSet<>();
            name1 = scanner.next();
            names.add(name1);
            name2 = scanner.next();
            names.add(name2);
            setOfpairsOfnames.add(names);
            System.out.println(setOfpairsOfnames.size());
        }
    
    }
    

    }