FastPrepAccount Balance Manager Part 1 - Calculate Totals

Account Balance Manager Part 1 - Calculate Totals

Stripe logoStripe● EasyFULLTIMENEW GRADINTERNONSITE INTERVIEW

Problem statement

Practice sequence

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

Reported transaction format

The linked interview report uses account_name,timestamp,currency,amount rows. Its examples are chronological and use one currency. Positive amounts add money and negative amounts withdraw money.

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 every account whose final balance is nonzero. This includes both positive and negative balances; omit only accounts whose final balance is exactly 0. Format each result as account_id:balance and sort the results lexicographically by account identifier.

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.

Reported example

The report uses four fields per row:

account_name,timestamp,currency,amount
acct_123,1,usd,1000
acct_123,2,usd,500
acct_321,3,usd,400
acct_321,4,usd,-400

Adding the signed amounts gives acct_123:1500; acct_321 ends at zero and is omitted. The report’s inconsistent account label is resolved from its input identifiers.

Function

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

Examples

Example 1

transactions = ["account_A,100", "account_B,50", "account_A,-30", "account_C,200", "account_B,-50", "account_D,-25"]return = ["account_A:70", "account_C:200", "account_D:-25"]

account_A ends at 70, account_B ends at 0, account_C ends at 200, and account_D ends at -25. The nonzero balances for account_A, account_C, and account_D are returned in lexicographic account order; only account_B is omitted.

Example 2

transactions = []return = []

An empty transaction list yields no accounts.

Example 3

transactions = ["acct_123,1000","acct_123,500","acct_321,400","acct_321,-400"]return = ["acct_123:1500"]

The second account’s400 deposit and400 withdrawal cancel; the first account receives1000+500. Only its nonzero balance is returned.

Constraints

  • Each transaction is "account_id,amount"; amount is an integer (positive deposit, negative withdrawal).
  • Process transactions in the given order, summing every amount for its account.
  • Return every account whose final balance is not 0, including accounts with negative final balances.
  • Omit an account only when its final balance is exactly 0.
  • Output entries are "account_id:balance" sorted lexicographically by account_id.
  • 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.

Source note: The supplied onsite screenshot explicitly says to print balances where balance != 0 before producing a rejection list.

More Stripe problems

See Stripe hiring insights
Saved
public String[] getAccountBalances(String[] transactions) {
  // write your code here
}
Checking account…