注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
09/18 校招投递
10/09 收到OA
10/10 做完OA,560/600
CodeSignal的 4-level OOD题,implement一个banking account system。和别的codesignal ood题相似(尤其是level 1和2,后面还有merge),不过level 3和4更难点.
- Create / Deposit accounts
- createAccount(timestamp, accountId): boolean
- Returnsif the account is created successfully.
- Returnsif an account withalready exists.
- deposit(timestamp, accountId, amount): Optional
- Returnsif the account doesn't exist.
- Otherwise, addsto the account's balance and returns the new balance.
- transfer(timestamp, sourceAccount, targetAccount, amount): Optional
- Returnsif eitherordoesn't exist.
- Returnsif
- sourceAccount == targetAccount
复制代码 . - Returnsif's balance is less than.
- Otherwise, movesfromtoand returns's remaining balance.
- Find top spenders
- topSpenders(timestamp, n): List
- Returns the topaccounts ranked by total outgoing amount, highest first.
- Outgoing = the sum of amounts sent via, plus amounts paid viafrom Level 3 on. It is not the number of transactions.
- Ties are broken byin lexicographic order.
- Ifexceeds the number of accounts, returns all accounts.
- Each entry is formatted[ DISCUZ_CODE_
- Sets that payment's status to "payment completed".
- Called at the start of every public method, so refunds always land first.
- : run the validations, then return.
Level 4 (didn’t finish debug)
- :
- Add'sandto.
- Instead of deletingfrom, set a new fieldon it.
- Existing logic gets an extra check: an account counts as nonexistent if it has been removed as of the call's timestamp.
- gets a new field,
- TreeMap<Integer, Integer> history
复制代码 : timestamp → balance. - The balance is recorded at the end of each function call, under that call's timestamp.
- : look upand return that balance.
|