add answers.md

This commit is contained in:
2026-06-10 07:25:17 +03:30
parent 2d457d8c0f
commit f3c9bf8876
2 changed files with 230 additions and 13 deletions
@@ -52,19 +52,7 @@ public class BankAccount {
}
}
/*
* TODO:
* Transfer money between two accounts atomically.
*
* IMPORTANT REQUIREMENTS:
* - Must be atomic (no partial transfer)
* - Must be deadlock-free
* - Must protect both source and target accounts
*
* HINT:
* - Consider global lock ordering using accountId
* - Or tryLock with retry strategy
*/
public void transfer(BankAccount target, long amount) {
BankAccount first = this.accountId < target.accountId ? this : target;
BankAccount second = this.accountId > target.accountId ? this : target;