educative.io

Correctness of solution for linked list intersection

Solution for finding intersection in linked lists seems to be invalid. I added values to make in test to add duplicates, as in task it says that solution should work with duplicates, unfortunately it seems there are no testcases that handle duplicates + solution does not seem to work for duplicates. Screen is attached. Is it intentional?

Hi @Alexei_Stirbul,

It works fine. If you change the 2nd list to 4->3->2->1->0 then it still returns 4 - three times. It is just checking if 4 is present in the 2nd list or not. We’re using the duplicates functionality for the union only.
Just a suggestion: If you want to handle the duplicates, you can first remove duplicates using removeDuplicatesWithHashing() function and then find the intersection.