Skip to content
RED SAGSkills
easy15 ptsfintechmath

Split a Bill to the Cent

Friends split a restaurant bill of totalCents between people people. Everyone pays a whole number of cents, the shares must add up to exactly totalCents, and no two shares may differ by more than one cent.

When the bill does not divide evenly, the extra cents go to the people at the start of the list, one cent each.

Return the array of people shares in order.

Example 1

Input: totalCents = 1000, people = 3
Output: [334,333,333]
Explanation: 1000 / 3 = 333 remainder 1, so the first person pays 334.

Example 2

Input: totalCents = 100, people = 4
Output: [25,25,25,25]

Constraints

  • 0 <= totalCents <= 10^9
  • 1 <= people <= 10^4
Hint 1

Everyone gets Math.floor(totalCents / people); the remainder tells you how many people pay one extra cent.

Discussion 0

Join free to post in the discussion.

Good practice for: Backend Developer, Full Stack Developer, Blockchain Developer, Data Engineer, Automation Test Engineer, Mobile App Developer, Frontend Developer

Run checks your code on 3 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.