Google | Phone | Money Movement

Interview for ML engineer role.

Let's say you have a dictionary like
{'John':400, 'Mary':-100, 'Kevin':250, 'Harry':50, 'Max':10, 'Jerry':80, 'Corey':200}

It has the following form
name: amount of money that person has

Create a function that MINIMIZES number of money movements, so that each person has at least 100. Assume that the input always guarantees such a solution exists. The function returns number of movements AND resulting dictionary. In case of tie, you can output any dictionary.

For instance in the above example, we will have

5,
{'John':200, 'Mary':100, 'Kevin':110, 'Harry':100, 'Max':100, 'Jerry':100, 'Corey':180}

as answer.

John gives 200 to Mary, Kevin gives 50 to Harry, Kevin gives 90 to Max, Corey gives 20 to Jerry, so it's 4 movements

Comments (2)