answer link: https://ide.codingblocks.com/s/50840
Please explain why it is giving tle after taking dp array also.
π‘ Exchanging Coins
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.