Banking System with Top Activity
Learn this problemProblem statement
Implement a banking system that processes a sequence of operations. Initially, the system contains no accounts. Each account has a balance and a financial-activity total, both starting at zero.
Each row of operations has one of these forms:
["CREATE_ACCOUNT", accountId]: If the account already exists, returnfalse. Otherwise, create it and returntrue.["DEPOSIT", accountId, amount]: If the account does not exist, return-1. Otherwise, addamountto its balance and activity, then return its updated balance.["TRANSFER", fromAccountId, toAccountId, amount]: Return-1if either account does not exist, both identifiers name the same account, or the sender has insufficient funds. Otherwise, moveamountfrom the sender to the recipient, addamountto both accounts' activity, and return the sender's updated balance.["TOP_ACTIVITY", n]: Return up tonaccount descriptions formatted asaccountId(activity). Order them by activity from highest to lowest, breaking ties byaccountIdin ascending alphabetical order. If fewer thannaccounts exist, return all accounts in that order.
An account's financial activity is the absolute sum of amounts from its successful deposits and transfers. A successful transfer contributes its amount to the activity of both endpoints. Unsuccessful transactions do not contribute activity.
Return one string array for every operation, in the same order. A scalar result is represented as a one-element array, such as ["true"] or ["2700"]; a TOP_ACTIVITY result contains its ranked account descriptions directly.
What the interview report shared
The report gave all four operation rules, the activity-ranking rule, and a complete operation/output sequence. This practice version is an estimated 95% match to that core task; the report did not include numeric limits or the original method and parameter names, so those details are not presented as source-provided.
Function
processBankingOperations(operations: String[][]) → String[][]Examples
Example 1
operations = [["CREATE_ACCOUNT","account1"],["CREATE_ACCOUNT","account1"],["CREATE_ACCOUNT","account2"],["DEPOSIT","non-existing","2700"],["DEPOSIT","account1","2700"],["TRANSFER","account1","account2","2701"],["TRANSFER","account1","account2","200"],["TRANSFER","account1","account2","2500"],["DEPOSIT","account2","300"],["CREATE_ACCOUNT","account3"],["DEPOSIT","account3","4000"],["TOP_ACTIVITY","3"],["DEPOSIT","account2","1000"],["TOP_ACTIVITY","2"],["TOP_ACTIVITY","5"]]return = [["true"],["false"],["true"],["-1"],["2700"],["-1"],["2500"],["0"],["3000"],["true"],["4000"],["account1(5400)","account3(4000)","account2(3000)"],["4000"],["account1(5400)","account2(4000)"],["account1(5400)","account2(4000)","account3(4000)"]]The first deposit gives account1 a balance and activity of 2700. The transfer of 2701 fails, while the transfers of 200 and 2500 succeed, leaving account1 with balance 0 and activity 5400. Those transfers give account2 activity 2700; after its deposit of 300, its balance and activity are 3000. With account3's deposit of 4000, the first ranking is therefore account1(5400), account3(4000), account2(3000).
After another deposit of 1000 into account2, accounts 2 and 3 both have activity 4000. Their tie is resolved alphabetically, so account2 comes first.
More Capital One problems
- Laser Robot Safe PathOA · Seen Jul 2026
- Longest Same-Character SubstringOA · Seen Jul 2026
- Match Consecutive Word BoundariesOA · Seen Jul 2026
- Rightmost Longest Character RunOA · Seen Jul 2026
- Track Received Byte RangesOA · Seen Jul 2026
- Compare Counts Around PivotOA · Seen Jul 2026
- Format a Newspaper PageOA · Seen Jul 2026
- Reconstruct Landmark JourneyOA · Seen Jul 2026