FastPrepCompute Platform Balance with Optional Destinations

Compute Platform Balance with Optional Destinations

Stripe logoStripe● EasyINTERNOA
Learn

Problem statement

Process a batch of charges and return the final amount retained by the platform.

Each charge is one comma-separated string with exactly three fields:

amount,destination_account,destination_amount

amount is the positive charge amount. The two destination fields are optional and may be empty.

  • If both destination fields are empty, the platform retains the full charge amount.
  • If destination_account is present and destination_amount is empty, the full charge amount is transferred away, so the platform retains zero.
  • If destination_amount is present, subtract that amount from the charge before adding the remainder to the platform balance. This rule also applies when destination_account is empty.

Return the sum retained by the platform across all charges.

What the interview report shared

The reported OA used optional destination-account and destination-amount parameters in a Platform Balance task. The candidate reasoned about three hidden cases: missing account, account without amount, and amount without account. Those diagnoses were tentative rather than confirmed rules.

Function

calculatePlatformBalance(charges: String[]) → long

Examples

Example 1

charges = ["100,,","80,shop_a,","120,shop_b,50","90,,20"]return = 240

The retained amounts are 100, 0, 70, and 70. Their sum is 240.

Example 2

charges = ["25,merchant_1,5","40,merchant_2,40","10,,0"]return = 30

The platform retains 20, 0, and 10.

Constraints

  • 1 <= charges.length <= 10^5.
  • 1 <= amount <= 10^9.
  • When present, 0 <= destination_amount <= amount.
  • A destination account contains lowercase English letters, digits, or underscores.
  • The final answer fits in a signed 64-bit integer.

More Stripe problems

See Stripe hiring insights
public long calculatePlatformBalance(String[] charges) {
    // write your code here
}
charges["100,,","80,shop_a,","120,shop_b,50","90,,20"]
expected240
Checking account…