Problem · Hash Table

Account Balance Manager Part 1 - Calculate Totals

Learn this problem
EasyStripe logoStripeFULLTIMEONSITE INTERVIEW
See Stripe hiring insights

Problem statement

Practice sequence

  1. Part 1: Calculate Totals (you are here)
  2. Part 2: Reject Overdrafts
  3. Part 3: Platform Coverage

What the interview report shared

The coding round centered on Account Balance / Bank Transaction and contained three questions.

Practice contract

For this exercise, assume transactions arrive in order as account_id,amount strings. A positive amount is a deposit and a negative amount is a withdrawal.

Process every transaction and calculate each account's final balance. Return only accounts with a strictly positive final balance. Format each result as account_id:balance and sort the results lexicographically by account identifier.

Function

getAccountBalances(transactions: String[]) → String[]

Examples

Example 1

transactions = ["account_A,100", "account_B,50", "account_A,-30", "account_C,200", "account_B,-50"]return = ["account_A:70", "account_C:200"]
account_A: 100 - 30 = 70 (positive, kept). account_B: 50 - 50 = 0 (zero, removed). account_C: 200 (positive, kept). Output sorted by account_id.

Example 2

transactions = []return = []
An empty transaction list yields no accounts.

Constraints

  • Each transaction is "account_id,amount"; amount is an integer (positive deposit, negative withdrawal).
  • Process transactions in the given order, summing per account.
  • Return only accounts with a final balance strictly greater than 0.
  • Output entries are "account_id:balance" sorted alphabetically by account_id.

More Stripe problems

drafts saved locally
public String[] getAccountBalances(String[] transactions) {
  // write your code here
}
transactions["account_A,100", "account_B,50", "account_A,-30", "account_C,200", "account_B,-50"]
expected["account_A:70", "account_C:200"]
checking account