Both test cases are correct for my code but 1st test case takes 4.83 s . can we do it better . please help . here is my code link :
Algo++ : Exchange coins
Hello @amandahiya.3572,
You were accessing the index n/2,n/3 and n/4, though these can also be float values.
Solution:
typecast them to long:
dp[i]=max(i,dp[(long)(i/2)]+dp[(long)(i/3)]+dp[(long)(i/4)]);
Hope, this would help.
Give a like, if you are satisfied.
I am getting right answer but the thing i am asking is my approach correct or there can be a better way to solve this problem
The most efficient way of doing this question is by using Dynamic Program Approach
as you have used in your program.