πŸ’‘ Exchanging Coins

question :https://hack.codingblocks.com/contests/c/512/721?_ga=2.165022911.1840443150.1548239118-665357574.1546102235

answer link: https://ide.codingblocks.com/s/50840
Please explain why it is giving tle after taking dp array also.

Please look at constraints of the question carefully.
Here n can be as large as 1000000000, for which the answer would be
4243218150, which can’t be stored in int.
So you need to use long. Your approach for DP is also not correct.

Go through this code which uses recursion, and try to build the DP solution from it.
https://ide.codingblocks.com/s/51691
Here despite using recursion, use of β€œif” saves a lot of recursive calls. Hence optimising the solution.