Run Details #701

Score

0

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

0/1

Incorrect (<100)

1

Median Time

10511.0ms

Tokens Used

477

Cost

526µ$

Run Date: 2026-03-02 23:55:49
Coding question results (1)
0304_python_coin_change:0 Incorrect
Score: 75 • 10511ms • 477 tokens • 526µ$
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 all(isinstance(coin, int) and coin > 0 for coin in coins):
        raise TypeError("Coins must be a list of positive integers.")

    # Sort the coins in descending order to use larger denominations first
    coins.sort(reverse=True)
    
    result = []
    for coin in coins:
        num_coins = amount // coin
        if num_coins > 0:
            result.extend([coin] * num_coins)
            amount %= coin
    
    if amount == 0:
        return len(result)
    else:
        raise ValueError("Exact change is not possible with the given coins.")
Test case results
# Status Args Expected Actual Error
0 Pass [78, [22, 4, 1]] 6 6 -
1 Pass [0, [22, 4, 1]] 0 0 -
2 Pass [8, [22, 4, 1]] 2 2 -
3 Pass [44, [22, 4, 1]] 2 2 -
4 Pass [23, [22, 4, 1]] 2 2 -
5 Pass [7, [4, 2]] ValueError ValueError -
6 Pass [11, [6, 5]] 2 2 -
7 Fail [10, [7, 5, 1]] 2 4 -
8 Fail [24, [7, 5, 1]] 4 6 -
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.