-
Notifications
You must be signed in to change notification settings - Fork 0
/
Challenge_9.txt
29 lines (20 loc) · 969 Bytes
/
Challenge_9.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Challenge: Union & Intersection of Linked Lists
Problem Statement
Union and intersection are two of the most popular operations which can be performed on data sets. Now, you will be implementing them for linked lists! Let’s take a look at their definitions:
Union
Given two lists, A and B, the union is the list that contains elements or objects that belong to either A, B, or to both.
Intersection
Given two lists, A and B, the intersection is the largest list which contains all the elements that are common to both the sets.
The union function will take two linked lists and return their union.
The intersection function will return all the elements that are common between two linked lists.
Input
Two linked lists.
Output
A list containing the union of the two lists.
A list containing the intersection of the two lists.
Sample Input
list1 = 10->20->80->60
list2 = 15->20->30->60->45
Sample Output
union = 10->20->80->60->15->30->45
intersection = 20->60