Multiply Two Polynomials - Problem
You are given two integer arrays poly1 and poly2, where the element at index i in each array represents the coefficient of xi in a polynomial.
Let A(x) and B(x) be the polynomials represented by poly1 and poly2, respectively.
Return an integer array result of length (poly1.length + poly2.length - 1) representing the coefficients of the product polynomial R(x) = A(x) * B(x), where result[i] denotes the coefficient of xi in R(x).
Input & Output
Example 1 — Basic Multiplication
$
Input:
poly1 = [1,2], poly2 = [3,4]
›
Output:
[3,10,8]
💡 Note:
Polynomial A(x) = 1 + 2x, B(x) = 3 + 4x. A(x) * B(x) = (1)(3) + (1)(4x) + (2x)(3) + (2x)(4x) = 3 + 4x + 6x + 8x² = 3 + 10x + 8x²
Example 2 — Single Coefficients
$
Input:
poly1 = [1,2,1], poly2 = [2]
›
Output:
[2,4,2]
💡 Note:
A(x) = 1 + 2x + x², B(x) = 2. A(x) * B(x) = 2(1 + 2x + x²) = 2 + 4x + 2x²
Example 3 — Zero Coefficients
$
Input:
poly1 = [1,0,1], poly2 = [1,1]
›
Output:
[1,1,1,1]
💡 Note:
A(x) = 1 + 0x + x² = 1 + x², B(x) = 1 + x. A(x) * B(x) = (1 + x²)(1 + x) = 1 + x + x² + x³
Constraints
- 1 ≤ poly1.length, poly2.length ≤ 100
- -100 ≤ poly1[i], poly2[i] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code