Sha256: 8289b39b467d7b5e12c54782edcfd1580025e2d1db357b02b2625a1ec3506638

Contents?: true

Size: 966 Bytes

Versions: 105

Compression:

Stored size: 966 Bytes

Contents

def find_minimum_coins(total_change, coins):
    if total_change < 0:
        return -1
    min_coins_required = [1e9] * (total_change + 1)
    last_coin = [0]*(total_change + 1)
    min_coins_required[0] = 0
    last_coin[0] = -1
    for change in range(1, total_change + 1):
        final_result = min_coins_required[change]
        for coin in coins:
            if coin <= change:
                result = min_coins_required[change - coin] + 1
                if result < final_result:
                    final_result = result
                    last_coin[change] = change - coin
        min_coins_required[change] = final_result
    if min_coins_required[total_change] == 1e9:
        return -1
    else:
        last_coin_value = total_change
        array = []
        while(last_coin[last_coin_value] != -1):
            array.append(last_coin_value-last_coin[last_coin_value])
            last_coin_value = last_coin[last_coin_value]
        return array

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
trackler-2.2.1.107 tracks/python/exercises/change/example.py
trackler-2.2.1.106 tracks/python/exercises/change/example.py
trackler-2.2.1.105 tracks/python/exercises/change/example.py
trackler-2.2.1.104 tracks/python/exercises/change/example.py
trackler-2.2.1.103 tracks/python/exercises/change/example.py
trackler-2.2.1.102 tracks/python/exercises/change/example.py
trackler-2.2.1.101 tracks/python/exercises/change/example.py
trackler-2.2.1.100 tracks/python/exercises/change/example.py
trackler-2.2.1.99 tracks/python/exercises/change/example.py
trackler-2.2.1.98 tracks/python/exercises/change/example.py
trackler-2.2.1.97 tracks/python/exercises/change/example.py
trackler-2.2.1.96 tracks/python/exercises/change/example.py
trackler-2.2.1.95 tracks/python/exercises/change/example.py
trackler-2.2.1.94 tracks/python/exercises/change/example.py
trackler-2.2.1.93 tracks/python/exercises/change/example.py
trackler-2.2.1.92 tracks/python/exercises/change/example.py
trackler-2.2.1.91 tracks/python/exercises/change/example.py
trackler-2.2.1.90 tracks/python/exercises/change/example.py
trackler-2.2.1.89 tracks/python/exercises/change/example.py
trackler-2.2.1.88 tracks/python/exercises/change/example.py