Account Balance Manager Part 2 - Reject Overdrafts
Updated
Problem statement
Practice sequence
- Part 1: Calculate Totals
- Part 2: Reject Overdrafts (you are here)
- Part 3: Platform Coverage
Transaction format
Rows use account_name,timestamp,currency,amount. They are chronological and use one currency. Positive amounts add money and negative amounts withdraw money.
Rules
For this exercise, assume transactions arrive in order as account_id,amount strings and every account starts with a balance of 0.
- Reject a transaction when applying it would make that account's balance negative, and leave the balance unchanged.
- Otherwise, accept the transaction and update the balance. A resulting balance of exactly
0is allowed.
Return the rejected transaction strings in their original order.
The runner projects each chronological, single-currency source row to account_id,amount. Timestamps and currency are omitted; do not infer sorting or currency-conversion behavior. The existing callable return format defines the judged task.
Interview follow-up: Include final balances
Follow-up: return the final nonzero balances after rejecting overdrafts. Keep the accepted-state balance map and, after all rows, list its nonzero entries. This follow-up is discussed alongside the runner’s rejection-only result.
account_name,timestamp,currency,amount
acct_123,1,usd,1000
acct_123,2,usd,500
acct_321,3,usd,400
acct_321,4,usd,-500The rejected original row is acct_321,4,usd,-500. The accepted final balances are acct_123:1500 and acct_321:400. The judged projection returns ["acct_321,-500"].
Complete report exercise
As an additional practice exercise, implement fullOverdraftReport(String[] transactions). Each input string has exactly four comma-separated fields account_name,timestamp,currency,amount, with no header. Rows are already chronological, all use one currency, and the account and numeric bounds above apply. Do not sort transactions or convert currency.
Return a String[][] with exactly two rows: row 0 contains the rejected original four-field strings in input order; row 1 contains final nonzero account:balance strings in ASCII lexicographic account order. Preserve each rejected row exactly. The workspace judges only rejectedTransactions on its two-field input; it does not grade this additional method.
For the four rows above, the full follow-up result is [["acct_321,4,usd,-500"],["acct_123:1500","acct_321:400"]]. The last withdrawal would produce 400 + (-500) = -100, so reject it and leave that account at 400.
Function
rejectedTransactions(transactions: String[]) → String[]Examples
Example 1
transactions = ["account_A,100", "account_A,-150", "account_B,50", "account_A,-80", "account_B,-100"]return = ["account_A,-150", "account_B,-100"]Step 1: account_A +100 -> 100 (ok). Step 2: account_A -150 -> would be -50 (REJECT). Step 3: account_B +50 -> 50 (ok). Step 4: account_A -80 -> 100-80=20 (ok). Step 5: account_B -100 -> would be -50 (REJECT). The two rejected transactions are returned in order.
Example 2
transactions = ["account_A,40", "account_A,-40", "account_A,-1"]return = ["account_A,-1"]account_A +40 -> 40 (ok). account_A -40 -> exactly 0, which is allowed (ok). account_A -1 -> would be -1 (REJECT). Only the last transaction is rejected.
Example 3
transactions = ["acct_123,1000","acct_123,500","acct_321,400","acct_321,-500"]return = ["acct_321,-500"]The final withdrawal would make acct_321 negative, so it is rejected and that account remains 400. The runner returns the projected two-field rejected row; the final-balance follow-up also yields acct_123:1500 and acct_321:400.
Constraints
- Each transaction is
"account_id,amount"with an integer amount. - Process in order; reject a transaction whose application would make the balance strictly negative.
- Deposits are always allowed; a result of exactly 0 is allowed.
- A rejected transaction does not change any balance.
- Return rejected transactions in order as
"account_id,amount". - For this practice domain, parsed amounts, all intermediate additions, balances, and negated shortfalls fit in a signed 64-bit integer. Account identifiers are nonempty ASCII strings without commas or colons.
More Stripe Onsite Interview questions
- Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Transaction Rule Expression EvaluatorONSITE INTERVIEW · Seen Oct 2026
- Evaluate Ordered Action RulesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- WebSocket Load Balancer — Parts 1–5OA · ONSITE INTERVIEW · Seen Sep 2026
- Rule-Driven Transaction Fraud DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Account Balance Manager Part 3 - Platform CoverageONSITE INTERVIEW · Seen May 2026
- Account Balance Manager Part 1 - Calculate TotalsONSITE INTERVIEW · Seen May 2026
- Merge and Filter Prioritized ConfigurationsONSITE INTERVIEW · Seen Apr 2026
Similar questions at other companies
- Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
- Card Transaction StreamCapital One · ONSITE INTERVIEWCapital One interview questions
- Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
- Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
- Generate Word Guess FeedbackAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Stable Unique Column RenamesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Dictionary Records to an Editable XML TreeSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions