Split a Shared Fare in Cents Without Losing Any Pennies

Last updated: November 29, 2026

Quick Overview

Given a total fare in cents and a list of riders' distance shares (positive integers), split the fare proportionally so the parts are whole cents, sum exactly to the total, and differ from the exact proportional amount by less than one cent. Leftover cents go to riders with the largest fractional remainders, ties by lower index.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a total fare in cents and a list of riders' distance shares (positive integers), split the fare proportionally so the parts are whole cents, sum exactly to the total, and differ from the exact proportional amount by less than one cent. Leftover cents go to riders with the largest fractional remainders, ties by lower index.

This mirrors UberX Share and split-fare features, where money must reconcile to the cent. The interviewer is checking integer-only arithmetic, a fair tie rule, and that you avoid floating point entirely.

What the Interviewer Expects
  • Refuses to use floats for money
  • Computes floor shares with integer division
  • Distributes remaining cents by largest remainder
  • Uses a deterministic tie-break
  • Proves the parts sum to the total
Key Topics to Cover
Integer arithmetic
Largest remainder method
Rounding
Sorting
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 handle a promo that discounts only one rider?
  • What if shares can be zero for a rider who cancelled?
  • How would you make the rounding stable so a rider's share does not jump when someone else's distance changes by a meter?
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: total (non-negative int, cents) and weights (list of positive ints). Output: list of ints, same length, summing to total. Each part must be within one cent of total * w_i / W where $W =...

High-Level Design

Exact share is total⋅wiW\frac{total \cdot w_i}{W}. Integer division gives the floor and the remainder r_i = total * w_i mod W. Floors sum to total - k for some k < n, because each floor loses less than...


Submit Your Answer
Markdown supported