Coin Change

For the problem https://leetcode.com/problems/coin-change/
Can we Solve using Recursion.
My Recursive approach is as follows

class Solution {
public:
    
    void countc(vector<int>& c,int index,int amount,int rem,int& count){
        
        
        if(rem==0){
            
            return;
        }
        
        if(index>=c.size() && rem>0){
              
            count=-1;
            return;
        }
        
        if(c[index]>rem){
            
            countc(c,index+1,amount,rem,count);
        }else{
        
        int val=rem/c[index];
       
        
        rem=rem-(val)*c[index];
        
        count+=val;
       
        countc(c,index+1,amount,rem,count);
            
            
        }
        
        
        return;
        
        
        
    }
    int coinChange(vector<int>& coins, int amount){
        
        if(amount==0){
            return 0;
        }
        
        sort(coins.begin(),coins.end(),greater<int>());
        
        
        
        int counts=0;
        
        countc(coins,0,amount,amount,counts);
        
        
        return counts;
        
    }
};

Can anyone please help if there is a way we can solve it using recursion

Comments (1)