Not Able to figure out the error

My code is running fine for custom inputs but when i submit it shows runtime error,I think it is because of the constraints that n can have very high values.Then I unlocked the editorial which is hard to understand for me and the editorial solution is giving answer 0 for any input.Please help.

Check the constraints
Constraints

0 <= n <= 1 000 000 000

Generally an array of size 10^9 cannot be made. But here n can range upto 10^9. So idea is to use hashmap for memo table and follow top down approach. Go through this discussion Exchanging coins

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.