Junior — Senior
Algorithm for dispensing banknotes from an ATM
livecode
Task condition
Given an object denominations, where keys represent banknote denominations and values are their available quantities. It is required to implement a function atmWithdraw(amount, denominations), which takes the target amount to dispense (amount) and an object with current banknote counts (denominations). The function should return a new object containing the set of banknotes needed to dispense the specified amount, in the same format as denominations. The original denominations object should be modified: the number of used banknotes should decrease. If it is impossible to assemble the required amount from the available banknotes, then:
- the denominations object remains unchanged;
- the function returns a string message indicating the impossibility of the withdrawal.