FastPrepRebalance Bank Accounts to a Minimum Balance
Problems/Rebalance Bank Accounts to a Minimum Balance

Rebalance Bank Accounts to a Minimum Balance

Stripe logoStripe● MediumFULLTIMENEW GRADINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Stripe onsite interview. The linked source gives the goal of keeping bank accounts above a threshold, a scale of at most 500, the requirement that the answer need not be optimal, a full input with five accounts, and the exact sequence of transfers that works. We turned the threshold of 100 into a parameter, and we made clear that the example uses the input order for its greedy choices. Our version is about 96% the same as the reported question. The extra follow-up about the fewest transfers comes from the original author of the first report. Each balance must be strictly above a variable target, and the follow-up asks for the fewest transfers. The author reported a discussion of backtracking that the interviewer accepted, without a full implementation that was checked. We supply a function with no grading, integer units, a total that works, direct transfer rules, and a limit of at most 12 accounts. The 96% describes the original version, not how complete this short follow-up is. A separate money-transfer report does not share its account state or threshold, so it is not counted for this exercise.

Stripe tracks money across bank accounts and sometimes moves funds so that every account stays at or above a required minimum balance.

Each input row is accountName,balance. Return a working sequence of transfers in the form from,to,amount that leaves every account with at least threshold.

An optimal number of transfers is not required. To get the same answer every time, handle the underfunded accounts in input order and take funds from the overfunded accounts in input order. Move as much as possible in each transfer without taking a donor below the threshold or raising the current receiver above it.

Follow-up: Minimum transfer count

The rebalanceAccounts method above stays the same. As an extra exercise that the tests do not check, implement minimumTransfersAboveTarget(accounts, target), returning an integer minimum number of transfers. Use the same accountName,balance row representation, but require each final balance to be strictly greater than the variable integer target.

For this follow-up, assume 1 to 12 uniquely named accounts, nonnegative integer balances and target at most 1,000,000, and enough total money: sum(balance) >= accounts.length * (target + 1). Any two distinct accounts may exchange a positive integer amount without making a balance negative. Only the count is returned; the order of an optimal sequence is irrelevant.

Because balances are integers, strictly greater than target means at least target + 1. This conversion applies to the follow-up only. The main method still uses its inclusive threshold argument, its input-order greedy order of transfers, and its existing 500-account limit.

For accounts = ["a,8","b,7","c,13","d,12"] and target = 9, return 2. Send 2 from d to a and 3 from c to b; every account then has at least 10. The main method with threshold 10 uses three input-order transfers, and that is still correct for its own task.

For accounts = ["a,0","b,2"] and target = 0, return 1: both accounts must finish at least 1. Returning zero would silently replace the strict target with an inclusive boundary.

Function

rebalanceAccounts(accounts: String[], threshold: long) → String[]

Examples

Example 1

accounts = ["AU,80","US,140","MX,110","SG,120","FR,70"]threshold = 100return = ["US,AU,20","US,FR,20","MX,FR,10"]

Every account needs at least the threshold. AU is short by twenty and FR by thirty. US has forty extra, so it first fills AU with twenty, then gives its remaining twenty to FR. FR still needs ten, and MX supplies it. So US sends twenty to AU, US sends twenty to FR, and MX sends ten to FR.

Example 2

accounts = ["a,50","b,50","c,200"]threshold = 100return = ["c,a,50","c,b,50"]

Accounts a and b are each fifty short, and c has a hundred extra. So c sends fifty to a, then fifty to b, in input order.

Constraints

  • 1 <= accounts.length <= 500.
  • Account names are unique and contain no commas.
  • 0 <= balance, threshold <= 10^12.
  • The total balance is at least accounts.length * threshold.
  • All arithmetic fits in signed 64-bit integers.
  • Extra exercise, minimum count: 1 <= accounts.length <= 12, with the same unique, comma-free account row format.
  • Extra exercise: integer 0 <= balance, target <= 1000000.
  • Extra exercise, enough money: sum(balance) >= accounts.length * (target + 1).
  • Extra exercise: positive integer transfers may connect any two distinct accounts without negative balances; return only the minimum count.
  • The bounds and transfer details of the extra exercise are as stated in the follow-up. The main bounds above are unchanged.

More Stripe Onsite Interview questions

  • Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Parse Boolean Rule ExpressionsPHONE 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 2 - Reject OverdraftsONSITE INTERVIEW · Seen May 2026
  • Account Balance Manager Part 1 - Calculate TotalsONSITE INTERVIEW · Seen May 2026

Similar questions at other companies

  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Container With Most WaterAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Assign Cookies With Matching ParityInfosys · ONSITE INTERVIEWInfosys interview questions
  • Container With Most WatereBay · ONSITE INTERVIEWeBay interview questions
  • Most Water Between Two LinesExpedia · ONSITE INTERVIEWExpedia interview questions
  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Container With Most WaterEPAM · PHONE SCREENEPAM interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • Container With Most WaterNuro · PHONE SCREENNuro interview questions
  • Minimum Last-Element RelocationsChubb · OAChubb interview questions

Interview reports that mention this question

  • Stripe SWE Intern Transfers and Bikemap Onsite: 1 Experience
  • Stripe Seattle SWE Intern Bank Transfer Offer: 1 Experience
  • Stripe SWE Intern Onsite Bikemap Round: 1 Experience
  • Stripe SWE Intern URL, Transfers and Bikemap: 1 Experience
  • Stripe New Grad Interview Question Bank: 47 Problems

Stripe interview experiences

  • Stripe New Grad SWE OA and Phone Screen: 2 Experiences
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String[] rebalanceAccounts(String[] accounts, long threshold) {
      // write your code here
    }
}
Checking account…