Money change problem

Ques link: https://hack.codingblocks.com/app/contests/1171/591/problem
Solution link: https://ide.codingblocks.com/s/244218

My approach is correct but i am getting run error in most of the test cases because my code is using more space!
please tell me how to correct it!