Run Details #676

Score

0

Correct (≥100)

0/1

Incorrect (<100)

1

Median Time

7292.0ms

Tokens Used

587

Cost

365µ$

Run Date: 2026-03-02 23:14:09
Coding question results (1)
0304_python_coin_change:0 Incorrect
Score: 0 • 7292ms • 587 tokens • 365µ$
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: int, coins: list[int]):
    """
    Finds the minimum number of coins needed to make the given amount exactly.

    Args:
        amount (int): The amount of money to make change for.
        coins (list[int]): A list of valid coin denominations.

    Returns:
        int: The minimum number of coins needed to make the amount exactly.

    Raises:
        ValueError: If the amount cannot be made with the given coins.
        TypeError: If the input is invalid.
    """

    # Initialize a minimum coin count to 0.
    min_coins = 0

    # Iterate through the coins in reverse order of their values.
    for coin in reversed(coins):
        # Check if the current coin can be used to make the amount.
        if amount >= coin:
            # Decrement the amount by the current coin value.
            amount -= coin
            # Increment the minimum coin count.
            min_coins += 1

    # Raise a ValueError if the amount cannot be made with the given coins.
    if amount != 0:
        raise ValueError("The amount cannot be made with the given coins.")

    # Return the minimum coin count.
    return min_coins


# Example usage.
print(min_coins_for_amount(44, [1, 2, 4]))
Test case results
# Status Args Expected Actual Error
0 Fail - - - Execution failed: ValueError