Coin Dispenser
Start Timer
0:00:00
Given a monetary amount in dollars and a list of coin denominations, write a function coin_exchange(amount: float, denominations: List[float]) -> List[Tuple[float, int]] that returns a list of tuples representing the optimal change amount. The denominations available for change can vary and are provided as input in the denominations list. A change is considered optimal when it returns the least possible count of denominations.
Note: The returned list of denominations should be in descending order, and in the case where there is no viable solution, return None.
Example:
Input:
amount = 14.61
denominations = [5.0, 2.0, 1.0, 0.50, 0.10, 0.05, 0.01]
Output:
coin_exchange(amount: float, denominations: List[float]) -> [(5.0, 2), (2.0, 2), (0.5, 1), (0.1, 1), (0.01, 1)]
.
.
.
.
.
.
.
.
.
Comments