Using tree recursion to solve coin change question

196 Views Asked by At

Given a positive integer change, a set of coins makes change for change if the sum of the values of the coins is change. We will use standard US Coin values: 1, 5, 10, 25.

I was asked to solve this coin change question with recursion function only(while and for loop are not allowed), and I am very struggling with it. Please help!

def next_smaller_coin(coin):
    """Returns the next smaller coin in order."""
    if coin = 25:
        return 10
    elif coin = 10:
        return 5
    elif coin = 5:
        return 1
      
def count_coins(change):
    if change == 0:
        return 1
    elif change < 0:
        return 0
    else:
        with_coin = count_coins(change - next_smaller_coin(coins))
        wo_coin = count_coins(change)
        return with_coin + wo_coin
0

There are 0 best solutions below