Split a Restaurant Check With Tip Into Exact Cents

Last updated: November 29, 2026

Quick Overview

Given a check subtotal in cents, an integer tip percentage, and a list of non-negative guest weights, return each guest's share in cents so the shares sum exactly to subtotal plus rounded tip.

Square
Coding & Algorithms
Software Engineer
Square
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a check subtotal in cents, an integer tip percentage, and a list of non-negative guest weights, return each guest's share in cents so the shares sum exactly to subtotal plus rounded tip.

Square for Restaurants lets a table split one check by seats or items, so money handling in integer minor units is a natural phone screen topic. The interviewer checks that you never use floats for money, that the parts always add back to the total, and that leftover cents are distributed deterministically.

What the Interviewer Expects
  • Work entirely in integer cents
  • Round the tip with an explicit, stated rule
  • Guarantee shares sum exactly to the total
  • Distribute leftover cents deterministically (largest remainder, ties by index)
  • Validate weights and handle a zero-weight guest
Key Topics to Cover
integer money
largest remainder method
rounding rules
invariants
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 split by items instead of weights, where tax applies per item?
  • What changes for a currency with zero minor units, like JPY?
  • How would you make the result stable if a guest is added mid-split?
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: subtotal_cents, integer tip_percent, and weights (seat counts or equal 1s). Output: a list of integer cents, one per guest, summing to subtotal + tip. Tip rounds half up to the nearest ...

High-Level Design

Compute the total once. Give each guest the floor of total * w / W using integer division, then hand out the cents lost to flooring (fewer than the number of guests) one at a time to the guests with...


Submit Your Answer
Markdown supported

Related Questions