Distribute Candies to People

Problem Id: 1103 Difficulty: Easy


Intuition

Solution


class Solution:
    def distributeCandies(self, candies: int, num_people: int) -> List[int]:
        ans = [0] * num_people
        index = 0
        n = 1
        while True:
            if candies < n:
                ans[index] += candies
                break
            ans[index] += n
            candies -= n
            n += 1
            index += 1
            if index >= num_people:
                index = 0
        return ans