Skip to content

Instantly share code, notes, and snippets.

@sanketsudake
Last active February 25, 2020 05:59
Show Gist options
  • Save sanketsudake/8c09c6cbb57360e98f1568b792846d82 to your computer and use it in GitHub Desktop.
Save sanketsudake/8c09c6cbb57360e98f1568b792846d82 to your computer and use it in GitHub Desktop.

The Problem

Alice and Bob have accounts at Bankgroup. Each account has 0 or more dollars in it.

Bankgroup wants to add a new “wire” feature, where any user can transfer money to any other user. This feature has the following requirements:

  • Each wire must be between two different people in the bank and wire at least one dollar.

  • If a wire is successful, the value of the wire is deducted from the sender account and added to the receiver account.

  • If the wire fails, the two accounts are unchanged.

  • A wire may not cause an account to have a negative balance.

  • For scaling reasons, multiple wires may happen simultaneously.

Your implementation must guarantee all properties, even if wires can take an arbitrary amount of time. In other words, even if wire A starts before B, A may still finish after wire B. Your algorithm must guarantee that, even in those cases, we satisfy all of the requirements. Given that money is on the line, you should probably design this in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment