Associated Course(s):
Interview Preparation
Sudo Placement [IITs]

Given two polynomial numbers represented by a linked list. The task is to complete the function **addPolynomial** that adds these lists meaning adds the coefficients who have same variable powers.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then in the next line is an integer N denoting the number of terms of first polynomial. In the next line are N space separated pairs x and y where x denotes the coefficient and y denotes the power. Similarly In the next line is an integer M denoting the no of terms of the second polynomial and in the line following it are N space separated pairs for second polynomial.

**Output:**

For each test case in a new line print the required polynomial in decreasing order of the power.

**Constraints:**

1 <= T <= 100

1 <= N, M <= 10^{5}

1 <= x, y <= 10^{6}

**Example:
Input:**

2

1

1 2

1

1 3

2

1 3 2 2

2

3 3 4 2

1x^3 + 1x^2

4x^3 + 6x^2

Author: Shubham Joshi 1

blackshadows | 242 |

layman_brother | 234 |

xmyqsh | 220 |

Adarsh Trivedi | 205 |

hanuman001 | 200 |

blackshadows | 724 |

xmyqsh | 561 |

aman19 | 402 |

r0c2048 | 360 |

mb1973 | 335 |

akhayrutdinov | 5005 |

Ibrahim Nash | 4875 |

Quandray | 4338 |

sanjay05 | 3668 |

blackshadows | 3228 |

Login to report an issue on this page.