Split a Group Order Bill Without Losing a Single Cent

Last updated: November 29, 2026

Quick Overview

Given each participant's item subtotal in cents and the final group order total (including fees, tax and tip), split the total in proportion to the subtotals so the shares are integers that sum exactly to the total.

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

0

0

0 solved


Given each participant's item subtotal in cents and the final group order total (including fees, tax and tip), split the total in proportion to the subtotals so the shares are integers that sum exactly to the total.

DoorDash Group Orders and split payments make this a realistic math and rounding question. Interviewers use it to see whether you avoid floating point money, know the largest remainder method, and can argue that the result is fair and deterministic.

What the Interviewer Expects
  • Work entirely in integer cents
  • Compute floor shares with exact integer division
  • Distribute leftover cents by largest remainder
  • Break remainder ties deterministically
  • Handle a zero-subtotal edge case
Key Topics to Cover
integer arithmetic
largest remainder method
rounding
payments
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
  • What if tip should be split evenly while tax and fees stay proportional?
  • How would you guarantee the person who paid the most never pays a rounding cent extra?
  • What changes if refunds later need to be split the same way?
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
  • Input: subtotals (non-negative ints) and total_cents.
  • Share for person i is ideally total * s_i / sum(s).
  • Output integer shares with sum(shares) == total_cents, each within one cent of i...
High-Level Design

For each person compute q, r = divmod(s_i * total, base) with integers, so there is no float error. The floors sum to at most total, short by leftover < n cents. Give one extra cent to the `left...


Submit Your Answer
Markdown supported