Problem
Implement an API in C to multiply two polynomials.
A polynomial is represented by its coefficients. You must define the input and output format as if you were writing a small library function for other users.
Example polynomials:
-
P(x)=x3−2x+5
-
Q(x)=x2+2x+4
Requirements
-
Use
C (not C++)
.
-
Define a clear representation for a polynomial (e.g., array of coefficients where
coeff[i]
is the coefficient of
xi
).
-
Provide a function (or set of functions) that multiplies two polynomials and returns the result.
-
Ensure the API handles:
-
Different degrees for the two inputs
-
Zero coefficients
-
Negative coefficients
Output
Return (or fill) a polynomial representing R(x)=P(x)×Q(x) using your chosen representation.
Constraints (you may assume)
-
Degrees are non-negative integers.
-
Coefficients fit in 32-bit signed integers (or specify a larger type if you choose).
-
Time complexity should be better than enumerating all exponent pairs explicitly as strings (i.e., use coefficient convolution).