Run Details #885

Score

0

Stored run score 92 recalculated to 0 after question exclusions.
Correct (≥100)

0/1

Incorrect (<100)

1

Median Time

9989.0ms

Tokens Used

548

Cost

499µ$

Run Date: 2026-03-03 19:32:38
Coding question results (1)
0304_python_coin_change:0 Incorrect
Score: 92 • 9989ms • 548 tokens • 499µ$
Question: Write Python 3.12 code only. Define exactly one function named min_coins_for_amount(amount, coins). Return the minimum number of coins needed to make the amount exactly. If exact change is impossible, raise ValueError. Raise TypeError for invalid input types. Do not use any imports (no numpy, requests, or other libraries). Sandbox note: dunder attribute access is blocked (for example, type(x).__name__). Avoid names/attributes starting with '__'. Expected output format: - Return exactly one fenced Markdown code block starting with ```python and ending with ```. - Put only valid Python code inside that block (no prose before/after). - Use 4 spaces for indentation (not tabs). - Do not return JSON and do not wrap code in a "function" key. Sample input/output behavior: - min_coins_for_amount(44, [1, 4, 22]) -> 2 Task: Write a Python 3.12 function for making change with the fewest coins (e.g., 78c with 1c, 4c, 22c).
Submitted code
def min_coins_for_amount(amount, coins):
    if not isinstance(amount, int) or amount < 0:
        raise TypeError("amount must be a non-negative integer")
    if not isinstance(coins, list):
        raise TypeError("coins must be a list")
    
    for coin in coins:
        if not isinstance(coin, int) or coin <= 0:
            raise TypeError("all coins must be positive integers")
    
    memo = {}

    def solve(target):
        if target == 0:
            return 0
        if target < 0:
            raise ValueError("cannot make negative amount with given coins")
        
        key = (target, len(coins))
        if key in memo:
            return memo[key]

        min_coins = float('inf')
        for coin in coins:
            remainder = target - coin
            if remainder >= 0 and solve(remainder) != float('inf'):
                current_coins = 1 + solve(remainder)
                if current_coins < min_coins:
                    min_coins = current_coins

        memo[key] = min_coins
        return min_coins

    result = solve(amount)
    if result == float('inf'):
        raise ValueError("exact change is impossible")
    
    return result
Test case results
# Status Args Expected Actual Error
0 Pass [78, [1, 4, 22]] 6 6 -
1 Pass [0, [1, 4, 22]] 0 0 -
2 Pass [8, [1, 4, 22]] 2 2 -
3 Pass [44, [1, 4, 22]] 2 2 -
4 Pass [23, [1, 4, 22]] 2 2 -
5 Pass [7, [2, 4]] ValueError ValueError -
6 Pass [11, [5, 6]] 2 2 -
7 Pass [10, [1, 5, 7]] 2 2 -
8 Pass [24, [1, 5, 7]] 4 4 -
9 Pass [3, [2]] ValueError ValueError -
10 Pass [10, '124'] TypeError TypeError -
11 Fail [-1, [1, 2]] ValueError TypeError amount must be a non-negative integer