Divide a sum of money as evenly as possible among recipients, capped by amounts owed.
Given an amount of money to distribute between multiple recipients and a map from recipient name to the amount owed to that recipient, write a function that divides the money as evenly as possible between the recipients. All money amounts are integers, and no recipient is paid more than they are owed.
Sample inputs and outputs: input: {'ryan': 10, 'stephanie': 10, 'quentin': 10, 'upeka': 10}, total=40 -> {'ryan': 10, 'stephanie': 10, 'quentin': 10, 'upeka': 10} input: {'ryan': 10, 'stephanie': 10, 'quentin': 10, 'upeka': 10}, total=20 -> {'ryan': 5, 'stephanie': 5, 'quentin': 5, 'upeka': 5} input: {'ryan': 2, 'stephanie': 10, 'quentin': 10, 'upeka': 10}, total=21 -> {'ryan': 2, 'stephanie': 6, 'quentin': 7, 'upeka': 6} input: {'ryan': 2, 'stephanie': 10, 'quentin': 10, 'upeka': 10}, total=22 -> {'ryan': 2, 'stephanie': 7, 'quentin': 7, 'upeka': 6}
Format · Technical screen; the same problem appears across Gusto SWE screens.
Community answers
Related courses


