1. You are given two linked lists with N and M nodes respectively.
2. Each linked list represent a polynomial number.
3. You have to write a function that adds the coefficients who have same
powers of the variable.
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 Lists. You can use
display to know its contents.
6. This is a functional problem. You have print the output in the function itself.
7. You should code only the addPolynomial function. It takes as input the
heads of the first and second linked list respectively. It should add the two
polynomials and print the output in the function itself.
8. Don't change the code of Node, main and display.Input Format
First line takes N, the number of elements in the first linked list. Second line takes input N space separated separated pairs x and y where x denotes the coefficient and y denotes the power. Third line takes M, the number of elements in the second linked list. Fourth line takes input M space separated separated pairs x and y where x denotes the coefficient and y denotes the power. Input is handled for you.
Output Format
For each test case in a new line print the required polynomial in decreasing order of the power.
Constraints
1 <= N <= 1000 1 <= M <= 1000 1 <= x, y <= 100
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
2 1 3 2 2 2 3 3 4 2
Output
4x^3 + 6x^2