Gusto | Software Engineer | USA

Anonymous User
539
Mar 27, 2025

Given an amount and receipts (name, desired_amount), distribute the amount across the recipients using the following criteria:

  1. The amount should be divided across recipients equally
  2. If it cannot be done equally, top receipents with the name sorted alphabetically should get their amount first.

Examples:

  1. Receipents: {a: 10, b: 10, c:10, d:10}, Amount: 40
  • Answer: {a: 10, b: 10, c:10, d:10} will get the desired amount as it can be divided equally
  1. Receipents: {a: 10, b: 10, c:10, d:10}, Amount: 33
  • Answer: {a: 9, b: 8, c:8, d:8} will be the answer as everyone will get 8 and 'a' will get 9 becasue it is alphabetically sorted
  1. Receipents: {a: 10, b: 10, c:10, d:10}, Amount: 33
  • Answer: {a: 9, b: 9, c:8, d:8} will be the answer as everyone will get 8 and 'a' and 'b' will get 9 becasue it is alphabetically sorted.

I assumed that the output of the last question will be {a: 10, b: 8, c:8, d:8} due to greedy approach but that was wrong.

Decision: Reject mostly due to invalid assumption.

Comments (2)