Driver Balance Ledger
Updated
Problem statement
Maintain an in-memory balance ledger for delivery drivers. Process each operation in order:
["ADJUST", driverId, delta]: add the signed integerdeltato the driver's current balance. A driver has balance0before the first adjustment.["BALANCE", driverId]: append the driver's current balance to the result. An unseen driver has balance0.["TOTAL"]: append the sum of every driver's current balance to the result.
Only BALANCE and TOTAL operations produce output. Return those values in operation order.
The total-balance operation may be called very frequently, so it should not scan every driver on each call.
Function
processDriverBalances(operations: String[][]) → long[]Examples
Example 1
operations = [["ADJUST","alice","1200"],["ADJUST","bob","800"],["TOTAL"],["BALANCE","alice"],["ADJUST","alice","-300"],["TOTAL"]]return = [2000,1200,1700]After the first two adjustments, the total is 1200 + 800 = 2000. Alice's balance is 1200. Her final adjustment lowers both her balance and the cached total by 300, so the last result is 1700.
Example 2
operations = [["BALANCE","d7"],["TOTAL"],["ADJUST","d7","-50"],["BALANCE","d7"],["TOTAL"]]return = [0,0,-50,-50]An unseen driver starts at 0, and an empty ledger also totals 0. Signed adjustments may make a balance and the overall total negative.
Example 3
operations = [["ADJUST","a","5"],["ADJUST","a","-5"],["ADJUST","b","9"],["TOTAL"],["BALANCE","a"],["BALANCE","b"]]return = [9,0,9]Repeated adjustments accumulate for the same driver. Driver a returns to 0, while driver b contributes the entire total of 9.
Constraints
1 <= operations.length <= 2 * 10^5.- Each operation has one of the documented forms.
- Each
driverIdcontains1to40ASCII letters, digits, hyphens, or underscores. - Each
deltais a decimal integer string between-10^9and10^9, inclusive. - Every individual driver balance and the total balance fit in a signed
64-bit integer.
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
- Config Store with Priority OverridesMicrosoft · PHONE SCREENMicrosoft interview questions
- ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Feature Flag EvaluationCVS Health · PHONE SCREEN
- In-Memory Key-Value Store OperationsOpenAI · PHONE SCREENOpenAI interview questions
- LRU CacheAthenahealth · PHONE SCREEN
- Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions