How can I further optimise it

def multiply_optimized(poly1, poly2):
if len(poly1) == 1 :
product = [poly1[0]* poly2[i] for i in range(len(poly2))]
return product
elif len(poly2) == 1 :
product = [poly2[0]* poly1[i] for i in range(len(poly1))]
return product
n = max(len(poly1),len(poly2))
poly1, poly2 = split(poly1, poly2)

    U = multiply_optimized(poly1[0],poly2[0])
    V = multiply_optimized(poly1[0],poly2[1])
    W = multiply_optimized(poly1[1],poly2[0])
    Z = multiply_optimized(poly1[1],poly2[1])
    product = add(U,add(increase_exponent(add(V,W),n//2), increase_exponent(Z,2*(n//2))))
    return product
1 Like

Well Here you have used the 4 operations method and in the assignment there is given a 3 operations method…which further optimises the solution…

You can implement this in your solution…and this should be fairly easy…but you may need to create a subtract function to do so…

If it is clear then Congratulations you have optimised it…
If it is not clear then I can send you my solution, if you reply so.

Hope this helps…

Can you share it I am a bit confused

Thank you

This is how I implemented it…

If you haven’t implemented the subtract funtion then it is also here,

Sorry for the wrong spelling of polynomial :sweat_smile: :sweat_smile: :sweat_smile:

If you are still confused then let me know, I’ll be happy to help…

Hey, I tried your code,but in evaluation it is failing test case 9