Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5701 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 938 |

@bt8816103042 | 739 |

@SHOAIBVIJAPURE | 428 |

@codeantik | 412 |

@SherlockHolmes3 | 407 |

@neverevergiveup | 348 |

@mahlawatep | 347 |

@shalinibhataniya1097 | 343 |

@murarry3625 | 333 |

@saiujwal13083 | 326 |

@rohitanand | 314 |

Complete Leaderboard |

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 the same variable powers.

**Note:** Given polynomials are sorted in decreasing order of power.

**Example 1:**

**Input:
**LinkedList1: (1,x^{2) }
LinkedList2: (1,x^{3})
**Output:
**1x^3 + 1x^2
**Explanation: **Since, x^{2} and x^{3} both have
different powers as 2 and 3. So, their
coefficient can't be added up.

**Example 2:**

**Input:
**LinkedList1: (1,x^{3}) -> (1,x^{2})
LinkedList2: (3,x^{3}) -> (4,x^{2})
**Output:
**4x^3 + 6x^2
**Explanation: **Since, x^{3} has two different
coefficients as 3 and 1. Adding them up
will lead to 4x^{3}. Also, x^{2} has two
coefficients as 4 and 2. So, adding them
up will give 6x^{2}.

**Your Task:**

The task is to complete the function **addPolynomial**() which should add the polynomial with same powers return the required polynomial in decreasing order of the power in the form of a linked list.

**Note**: Try to solve the question without using any extra space.

**Expected Time Complexity:** O(N+M)

**Expected Auxiliary Space:** O(1)

**Constraints:**

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

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

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Polynomial Addition

...