Gotta Snatch 'Em All (wrong solution pass all tests)

This solution pass all tests:

    static Set<String> commonCards(List<Set<String>> collections) {
        Set<String> returnSet = new HashSet<>();
        if (collections.size() == 1){
            return collections.get(0);
        }
        
        for(int i = 0; i < collections.size()-1; i++){
            for (String card : collections.get(i)) {
                if (collections.get(i+1).contains(card)){
                    returnSet.add(card);
                }
            }
        } 
        return returnSet;
    }

The loops check if a card in collection i is present in collection i+1 . However, to find the common cards across all collections, a card must be present in every single set.

Should we add more test cases?

Is this problem specific to the Java track or does this apply to many tracks via the problem spec?

I believe there’s no “Gotta Snatch 'em All” in the problem spec.

That’s a concept exercise so it’s specific to the Java track. Therefore, the Java track maintainers’ input is needed here since they decide whether a PR is needed or not.

CC @kahgoh @jagdishdrp @sanderploegsma

1 Like

Moved to the Java category

What about updating testCommonCardsMultipleCollections instead? The first and last sets in the list happen to have Mayofried that isn’t in the middle set. I think the list can be re-ordered to also pick this up.

1 Like
1 Like