Polynomial Addition
Background
Polynomial addition involves adding the coefficients of matching degree terms. If the polynomials have different degrees, the missing higher-degree terms can be treated as having a coefficient of 0.
Task
Write a function poly_add(poly1, poly2) that returns the sum of two polynomials. Both polynomials are given as lists of coefficients from highest to lowest degree.
Specifications
- The function takes two lists of coefficients
poly1andpoly2. - It should return a new list representing the sum of the polynomials.
- The resulting list should not have leading zeros unless the polynomial is exactly 0.
Constraints
poly1andpoly2will not be empty.- The output should be normalized to not have unnecessary leading zeros.
Example
Instructions
- Implement the logic in
solution.py. - Do not use
input()orprint(). - Test your solution locally before submitting.