Distribute Candies to People
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You have candies candies to hand out to num_people people standing in a row, numbered 0 to
num_people - 1.
Walk along the row repeatedly. The first gift is 1 candy (to person 0), the second gift is 2 candies
(to person 1), and so on: every gift is one candy larger than the previous one, and after the last
person you wrap back to person 0 and keep going. When the next gift would be larger than the candies
left, the current person gets all the remaining candies and the process stops.
Return an array of length num_people whose i-th entry is the total number of candies person i
received.
Examples
Constraints
- 1 <= candies <= 10^9
- 1 <= num_people <= 1000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.