LeetCode solutions

1195. Distribute Candies to People

My accepted C++ solution to LeetCode problem 1195, Distribute Candies to People, running in 0ms.

  • Difficulty: Easy
  • C++
  • Runtime 0ms
  • Memory 8.9MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 8.9MB, accepted 2025-12-28.

cpp
class Solution {
public:
    vector<int> distributeCandies(int candies, int num_people) {
        vector<int> result(num_people, 0);
        int give = 1;
        int i = 0;
        while (candies > 0) {
            result[i % num_people] += min(give, candies);
            candies -= give;
            give++;
            i++;
        }
        return result;
    }
};

Source