Good morning! Here's our prompt for today.
Assume you have a Linked List implementation that has the following API:
JAVASCRIPT
1// prepend to start of list
2#prepend(val);
3
4// appends to end of list
5#append(val);
6
7// get an array of node values (for testing)
8#toArray();Can you write a method getIntersection(list1, list2) to find the intersection of two linked lists?

The return value should be a new linked list.
Constraints
- Length of the two linked lists <=
1000 - The nodes in the list will always contain integer values between
-1000000000and1000000000 - Expected time complexity :
O(n*m)(the lengths of the two lists) - Expected space complexity :
O(n)
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx59
​class Node: def __init__(self, val): self.val = val self.next = None​​def get_intersection(list1, list2): # fill this method in​ return list1​​# Node definitionclass Node: def __init__(self, val): self.val = val self.next = None​​def create_nodes(head, nodes): for val in nodes: new_node = Node(val) head.next = new_node head = new_node​​list1 = Node(3)nodes1 = [4, 5, 6, 7, 8, 9, 10]create_nodes(list1, nodes1)OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Here's how we would solve this problem...
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

