Split a Bill Without Losing Paise

Hard ⏱ 18 min 34% acceptance ★★★★☆ 4.4
Write split_bill(total_paise, n) dividing an integer amount of paise among n people so shares differ by at most 1 paise and sum exactly to the total — floats would leak money. The first total % n people carry the extra paise.

Examples

Example 1
Input
split_bill(1000, 3)
Output
[334, 333, 333]
Explanation

The remainder paise goes to the first person; the sum is exactly 1000.

Constraints

  • Work in integer paise only.
  • sum(result) == total_paise, guaranteed.

Topics

Business Logicmoney precision

Companies

SplitwisePaytmGoogle Pay Team

Hints

Hint 1

divmod(total, n) gives base share and remainder.

Hint 2

First r people get base+1.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.