Split a Charge Across Recipients in Whole Cents by Weight

Last updated: November 29, 2026

Quick Overview

Split an integer amount of cents across recipients in proportion to integer weights so the parts sum exactly to the total, assigning leftover cents by largest remainder with a deterministic tie-break.

Stripe
Coding & Algorithms
Software Engineer
Stripe
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Split an integer amount of cents across recipients in proportion to integer weights so the parts sum exactly to the total, assigning leftover cents by largest remainder with a deterministic tie-break.

Stripe Connect platforms split one customer payment across sellers, and tax or discounts are allocated across invoice line items, so every split must reconcile to the cent. The interviewer checks that you avoid floats, guarantee the sum invariant and make the result deterministic so retries and audits produce the same numbers.

What the Interviewer Expects
  • Use exact integer arithmetic (`divmod` on `total * w` by the weight sum)
  • Guarantee that the parts always sum to the total
  • Distribute leftover cents greedily by largest remainder, breaking ties by index
  • Handle negative totals (refunds) symmetrically with positive ones
  • Reject or explain an all-zero weight vector
Key Topics to Cover
greedy
integer arithmetic
largest remainder method
money handling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you enforce a minimum share per recipient, for example a platform fee floor?
  • Why might rounding-to-nearest per recipient fail the sum invariant?
  • How would you make a partial refund reverse the original split consistently?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Inputs: total in cents (may be negative for refunds) and a list of non-negative integer weights with a positive sum. Output: a list of integer cents, one per recipient, summing to total, each with...

High-Level Design

Work on abs(total) and reapply the sign at the end, so a refund mirrors its charge. For each weight compute q, r = divmod(amount * w, W). The floors leave amount - sum(q) cents unassigned, alway...


Submit Your Answer
Markdown supported