

The first line of input contains an integer ‘T’, the number of test cases.
The first line of each test case contains the linked list separated by space and terminated by -1.
The second line of each test case contains an integer ‘M’, representing the size of the array ‘ARR’.
The third line of each test case contains ‘M’ space-separated integers, representing the array ‘ARR’.
For each test case, print the number of connected components.
Output for each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 3*10^3
1 <= M <= N
The linked list consists of unique integers only.
Time Limit: 1 sec
The idea is to traverse the linked list and check whether the value of the nodes is present in the array or not. We also use a map to store the values of the array so as to access them in constant time.
Here is the algorithm :
HELPER(TEMP, CHECK, MP):
This approach is similar to the previous approach. We traverse the linked list iteratively to check for the connected components.
Here is the algorithm :