Not Accepting my Answer

A user asked us the following question:

def recursive_multiply(x, y): if y == 0: return 0 return x + recursive_multiply(x, y-1) May I know why this solution is not accepted

This exercise evaluates the efficiency of the solution along with correctness so the solution has to be correct plus optimized. In one of the test cases, x equals 500 while y equals 2000 . If our solution is making y recursive calls rather than making x recursive calls, then our solution is expensive. To cut the recursive calls and make the solution cost-effective, we can swap x and y accordingly as yx or xy imply the same.

Best Regards,
Alina Fatima | Developer Advocate

1 Like

I wish that would have been emphasized in the question prompt. Nowhere did it say the solution had to be optimized, and as a result I wasted so much time figuring out why a simple solution kept leading to a seemingly infinite recursion. It is very unfortunate that a user has to be punished for using a correct answer simply because Educative didn’t specify they wanted it in a specific way. I hope this exercise page gets edited to save others’ time.