![]() |
VOOZH | about |
Given a polynomial as a string and a value. Evaluate polynomial's derivative for the given value.
Note: The input format is such that there is a white space between a term and the '+' symbol
The derivative of p(x) = ax^n is p'(x) = a*n*x^(n-1)
Also, if p(x) = p1(x) + p2(x)
Here p1 and p2 are polynomials too
p'(x) = p1'(x) + p2'(x)
Input : 3x^3 + 4x^2 + 6x^1 + 89x^0 2 Output :58 Explanation : Derivative of given polynomial is : 9x^2 + 8x^1 + 6 Now put x = 2 9*4 + 8*2 + 6 = 36 + 16 + 6 = 58 Input : 1x^3 3 Output : 27
We split the input string into tokens and for each term calculate the derivative separately for each term and add them to get the result.
59
Time Complexity: O(n), where n is the number of terms in the polynomial.
Auxiliary Space: O(1)