FunctionRacerProblemsRace

Distribute Candies to People

EasyMathPython, JavaScript, TypeScript, Java, C++

You hand out candies to people children standing in a row. Give 1 candy to the first, 2 to the second, and so on, going back to the first child after the last and continuing to increase the amount by 1 each time (so the next gift is people + 1). When fewer candies remain than the next gift, give all the remaining candies to the next child and stop. Return how many candies each child ends up with.

Example 1

candies 7
people 4
returns [1,2,3,1]

Gifts 1, 2, 3, then the last 1 candy to child 4: [1, 2, 3, 1].

Example 2

candies 10
people 3
returns [5,2,3]

Gifts 1, 2, 3, 4: [5, 2, 3].

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems