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?