A user said the following:
A better solution for the challenge is something like this:
string Intersection(DoublyLinkedList list1, DoublyLinkedList list2) {
DoublyLinkedList list3;
map MP;
for (auto current = list1.getHead(); current != nullptr; current = current->;nextElement)
MP[current->data] = 1;
for (auto current = list2.getHead(); current != nullptr; current = current->nextElement) {
if(MP[current->data])
list3.insertAtTail(current->data);
}
return list3.elements();
}