Homework Lesson 24 : Identify a Suspect

Hi Guys, I am having a hard time to solve the homework lesson 24.

According to the homework, the function should return a list of the people who are at least included in the 2 lists. I am not sure where did I go wrong with this code.

I humbly ask assistance with this matter. This is my code.

Set calculateSuspects(Set b1, Set b2, Set b3) {
Set s = new HashSet<>(b1);
s.addAll(b2);
s.addAll(b3);
Set temp = new HashSet<>(b1);
temp.addAll(b2);
temp.addAll(b3);
s.retainAll(temp);
return s;
}
the error shows this.

Ran 64 tests. Stopped after finding 1 failure:

Testing calculateSuspects(Set b1 = [Sue, Bob, Rob], Set b2 = [Sue, Rob, Helen], Set b3 = [Bob]) failed:
Solution returned: [Sue, Rob, Bob]
Submission returned: [Sue, Bob, Rob, Helen]

Thank you so much.

Hi found the answer. You should need to create 3 union of the sets and use retainall no need to reply. Thanks.

2 Likes