Exchanging Coins Question

This question is to be solved using dp (storage array) but n is very large and its giving out of memory error in java. Pls explain the correct method. Here is my code:

Hey Yash
use HashMap instead of arrayList

still same error out of heap memory

use Top-down dp and HashMap, it will work

Thank you, it worked!

Please mark your doubts as resolved in your course’s.