Given amount of money to distribute between multiple recipients and given a map that maps the recipient name to amount of money owed to that recipient, write a function that divides the money as evenly as possible between the recipients (all money amounts are supposed to be integers):
Example:
**INPUT**:
AMOUNT TO DISTRIBUTE: 45,
AMOUNTS OWED: {'Recipient A': 30, 'Recipient B': 10, 'Recipient C': 10, 'Recipient D': 14}
**OUTPUT**:
DISTRIBUTION: {'Recipient A': 12, 'Recipient B': 10, 'Recipient C': 10, 'Recipient D': 13}NOTES:
Of course, to solve it, one needs to know what "to divide the money as evenly as possible" means in this context.
After poking the interviewer for couple of minutes, I managed to get precise definition from them:
Result of the distribution should be the same as if created by the following procedure:
- Order the recipients
- Do distribution in rounds. Each round adds 1 unit of money to each recipient in order untill all money are exhauseted.
- If the owed amount is reached for a recipient diring a round of distribution, the recipient is excluded from all following rounds. Order of remaining recipients is preserved.
Of course, it is trivial to implement the procedure as stated. The challenge is to implement distribution in efficient manner.
Comments (12)


