1. You are given a singly linked list containing N unique integer nodes .
2. You are also given G numbers which are a subset of values in linked list.
3. You have to write a function that return the number of connected components
in G, where two values are connected if they appear consecutively in the
linked list.
4. display is a utility function which displays the contents of Linked List,
feel free to use it for debugging purposes.
5. main takes input from the users and creates the Linked List. You can use
display to know its contents.
6. This is a functional problem.
7. You should code only the numComponents function. It takes as input the
head of the linked list and an array G. It should return the number of
connected components in G.
8. Don't change the code of Node, main and display.Input Format
First line takes N, the number of elements in the list. Second line takes input N space separated numbers reperesenting elements of the linked list. Third line takes input G, the number of elements in subset. Fourth line takes input G space separated numbers reperesenting elements of the linked list. Input is handled for you.
Output Format
number of connected components in G. Output is handled for you.
Constraints
1 <= N <= 1000 1 <= G <= N
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
5 0 1 2 3 4 4 0 3 1 4
Output
2