Split a Marketplace Payment Across Sub-Merchants Without Losing Cents
Last updated: November 29, 2026
Quick Overview
Given a captured amount in minor units and integer weights for each receiving account, split the amount so each share is as close as possible to its proportional value and the shares sum exactly to the total.
Adyen
November 29, 20260
0
0 solved
Given a captured amount in minor units and integer weights for each receiving account, split the amount so each share is as close as possible to its proportional value and the shares sum exactly to the total.
Adyen for Platforms lets a marketplace split one shopper payment between sellers, the platform commission and other balance accounts. The interviewer wants integer-only money arithmetic, a deterministic rounding rule that never creates or destroys a minor unit, and awareness of currencies with different exponents.
What the Interviewer Expects
- Work in integer minor units and refuse floating point for money
- Use floor division and distribute the leftover units by largest remainder
- Make tie-breaking deterministic so retries give identical results
- Prove the shares always sum to the total
- Validate weights and amounts and explain behaviour for zero weights
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you handle a currency with zero decimals such as JPY versus three decimals such as KWD?
- The platform wants its commission rounded down and sellers to absorb the remainder. How does the algorithm change?
- How would you split a later partial refund so it mirrors the original split?
- What if one split must be a fixed amount and the rest proportional?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: total as a non-negative integer in minor units (cents for EUR) and a map of account to non-negative integer weights with a positive sum. Output: a map of account to integer amounts where eve...
High-Level Design
Compute each exact share as a fraction total * w / W. Give every account the floor, which can leave at most len(accounts) - 1 units unassigned. Hand those units one at a time to the accounts with ...