educative.io

Educative

Given solution for intersection seems to be wrong

In the intersection solution , when we find an element present in both list (contains returns true) we are inserting the duplicate element at the headNode of the result , what happends when there is another duplicate node in the list now we have two elements in intersection but the resultNode head will only point to the second one

list1 :: 1 → 2 → 3 → 4
list2 :: 1 → 6-> 4-> 5->

intersection of list1 and list2 should give 1 , 4

but if we use the soln we will get only 4


Course: Educative: Interactive Courses for Software Developers
Lesson: Educative: Interactive Courses for Software Developers

Hello Vineeth,

We have cross checked the solution and the code. It’s working fine on our end. Please have a look again.
Output: