Compute the derivative of a polynomial. Given a polynomial represented as a list of coefficients (from highest degree to lowest), return the coefficients of its derivative.
def derivative_of_polynomial(coefficients: list[float]) -> list[float]:
n = len(coefficients)
if n <= 1:
return [0]
degree = n - 1
result = []
for i, coeff in enumerate(coefficients[:-1]):
power = degree - i
result.append(coeff * power)
if not result:
return [0]
return resulta * x^n is a * n * x^(n-1).[3, 2, 1] represents 3x^2 + 2x + 1.3x^2 + 2x + 1 is 6x + 2, returned as [6, 2].