Problem · Hash Table

Account Balance Manager Part 3 - Platform Coverage

MediumStripeONSITE INTERVIEW
See Stripe hiring insights

This continues the account balance manager. You are given a list of transactions in order (each "account_id,amount") and the id of a special platform_account.

Now, instead of rejecting a withdrawal that would make a user's balance negative, the platform covers the shortfall: transfer exactly enough money from the platform account so the user's balance ends at exactly 0. The transaction still happens (the user balance becomes 0), the platform account is debited by the shortfall, and you accumulate the covered amount.

The platform account itself behaves like a normal account for its own transactions — only regular users are covered, never the platform. Assume the platform account always has enough money.

Return the total amount the platform account had to pay across all transactions, as an integer.

Examples
01 · Example 1
transactions = ["platform,1000", "account_A,100", "account_A,-150", "account_B,50", "account_B,-100", "account_A,-30"]
platformAccount = "platform"
return = 130
platform +1000 -> 1000. account_A +100 -> 100. account_A -150 -> would be -50, platform pays 50, account_A becomes 0 (covered total 50). account_B +50 -> 50. account_B -100 -> would be -50, platform pays 50, account_B becomes 0 (covered total 100). account_A -30 -> would be -30, platform pays 30, account_A becomes 0 (covered total 130). Total covered = 130.
02 · Example 2
transactions = ["platform,500", "account_A,20", "account_A,-20"]
platformAccount = "platform"
return = 0
account_A +20 -> 20, then -20 -> exactly 0, which does not go negative, so no coverage is needed. The platform pays nothing.
Constraints
  • Each transaction is "account_id,amount" with an integer amount.
  • When a non-platform account would go negative, the platform covers the shortfall so that account ends at exactly 0, and the platform account is debited by that shortfall.
  • The platform account is treated as a normal account for its own transactions and is never itself covered.
  • Assume the platform always has enough money.
  • Return the total amount paid by the platform as an integer.
More Stripe problems
drafts saved locally
public int processWithCoverage(String[] transactions, String platformAccount) {
  // write your code here
}
transactions["platform,1000", "account_A,100", "account_A,-150", "account_B,50", "account_B,-100", "account_A,-30"]
platformAccount"platform"
expected130
sign in to submit