Bank Accounts with Transfers and a Richest Lookup
Updated
Problem statement
Build a small bank. Each account has a whole-number id and a balance. Process the operations in order and return one number for each operation. A result of -1 means the operation failed and changed nothing.
"open"withargs[i] = [id]: open a new account with balance0and return0. If an account with this id is already open, return-1."deposit"with[id, amount]: addamountto the account and return its new balance. Return-1if the account is not open. A deposit never opens an account."withdraw"with[id, amount]: takeamountout of the account and return its new balance. Return-1if the account is not open or its balance is less thanamount. Taking out the whole balance is allowed."transfer"with[fromId, toId, amount]: moveamountfrom accountfromIdto accounttoIdand return the new balance offromId. Return-1iffromIdandtoIdare the same, if either account is not open, or if the balance offromIdis less thanamount."richest"with[]: return the id of the open account with the highest balance. If several accounts tie, return the smallest id. Accounts with balance0count too. Return-1if no account is open.
Balances can grow larger than a 32-bit integer can hold.
Function
runBank(operations: String[], args: int[][]) → long[]Examples
Example 1
operations = ["open","open","deposit","deposit","richest","withdraw","richest","transfer","richest"]args = [[7],[3],[7,500],[3,300],[],[7,200],[],[7,3,300],[]]return = [0,0,500,300,7,300,3,0,3]Accounts 7 and 3 open with 0. After the deposits, 7 has 500 and 3 has 300, so the richest is 7. Withdrawing 200 leaves 7 with 300: now both hold 300, and the smaller id, 3, wins. Account 7 then sends all of its 300 to account 3. Sending exactly the whole balance is allowed, and the transfer returns the sender's new balance, 0. Account 3 now holds 600 and is the richest.
Example 2
operations = ["richest","open","open","deposit","withdraw","deposit","withdraw","transfer","transfer","richest"]args = [[],[5],[5],[9,100],[5,1],[5,40],[5,40],[5,5,10],[5,8,10],[]]return = [-1,0,-1,-1,-1,40,0,-1,-1,5]No account exists yet, so richest returns -1. Opening 5 works, but opening 5 again fails. Account 9 was never opened, so the deposit fails and does not create it. Account 5 has 0, so withdrawing 1 fails. After a deposit of 40, withdrawing exactly 40 works and leaves 0. A transfer from 5 to itself fails, and so does a transfer to account 8, which does not exist. Account 5 still counts for richest even with a balance of 0.
Example 3
operations = ["open","open","deposit","deposit","deposit","transfer","richest","transfer","richest"]args = [[1],[2],[1,1000000000],[1,1000000000],[1,1000000000],[1,2,1000000000],[],[1,2,1000000000],[]]return = [0,0,1000000000,2000000000,3000000000,2000000000,1,1000000000,2]Three deposits of 1,000,000,000 give account 1 a balance of 3,000,000,000, which is too big for a 32-bit integer. After one transfer, account 1 has 2,000,000,000 and account 2 has 1,000,000,000, so 1 is the richest. After the second transfer, account 1 has 1,000,000,000 and account 2 has 2,000,000,000, so 2 is the richest.
Constraints
1 <= operations.length <= 1000andargs.length == operations.length- Each
operations[i]is"open","deposit","withdraw","transfer"or"richest". args[i]has 1 number for"open", 2 for"deposit"and"withdraw", 3 for"transfer", and none for"richest".- Every id and every amount is between
1and10^9.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
- Design Authentication ManagerApple · PHONE SCREENApple interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
- Tiered Expiring Item StoreAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Multi-Level Inventory Storage SystemOptiver · OA · PHONE SCREENOptiver interview questions
- Limit Order Book Matching EngineCitadel · PHONE SCREENCitadel interview questions
- Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions
Interview reports that mention this question
Rippling interview experiences
- Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
- Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
- Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
- Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)
- Rippling SWE Interviews, No Level: 156 Experiences (Part 1 of 6)