Given two polynomials represented by two linkedlists that contains the coefficients of poynomials. Your task is to complete the method **proOfPolynomials()** which takes four arguments: the address of the head of the linked list1, the address of the head of the linked list2, size of linked list1 and size of linked list2. The function returns the head of a linked list formed after multiplication of given polynomials.

**Input:**

The first line contains an integer T, depicting total number of test cases. First line of each test case contains two integers M and N,highest degree of the polynomial linked list1 and linked list2. Next two line contains M and N integers , decribes the coefficients of polynomials.

**Output:**

Print the coefficients of resultant poynomial.

**User Task:**

The task is to complete the function **proOfPolynomials**() which should multiply the given polynomial.

**Constraints:**

1 <= T <= 100

1 <= M, N <= 100

1 <= size of list1 & list2 <= 100

**Example:**

**Input:**

2

4 3

1 0 3 2

2 0 4

5 4

1 9 3 4 7

4 0 2 5

**Output:**

2 0 10 4 12 8

4 36 14 39 79 23 34 35

**Explanation:**

**Testcase 1:**

First polynomial:

1 + 0x^1 + 3x^2 + 2x^3

Second polynomial:

2 + 0x^1 + 4x^2

Product polynomial:

2 + 0x^1 + 10x^2 + 4x^3 + 12x^4 + 8x^5

**Testcase 2:**

First polynomial:

1 + 9x^1 + 3x^2 + 4x^3 + 7x^4

Second polynomial:

4 + 0x^1 + 2x^2 + 5x^3

Product polynomial:

4 + 36x^1 + 14x^2 + 39x^3 + 79x^4 + 23x^5 + 34x^6 + 35x^7

Author: Amit Khandelwal 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

preparecodinginterview_dot_com | 190 |

__murugan__ | 173 |

manvimahajan20 | 140 |

xiaoyan_yunche | 139 |

ShameekAgarwal | 116 |

preparecodinginterview_dot_com | 190 |

__murugan__ | 173 |

manvimahajan20 | 166 |

SoumyaKaushik | 146 |

arpit_anshuman | 140 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.