package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/distribute-candies-to-people/
 */
public class Problem1103 {
    public int[] distributeCandies(int candies, int num_people) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1103 prob = new Problem1103();
        System.out.println(Arrays.toString(prob.distributeCandies(7, 4))); // [1,2,3,1]
        System.out.println(Arrays.toString(prob.distributeCandies(10, 3))); // [5,2,3]
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/distribute-candies-to-people/
 */
public class Problem1103 {
    public int[] distributeCandies(int candies, int num_people) {
        int[] answer = new int[num_people];
        int i = 0;
        while (candies >= 0) {
            int index = i % num_people;
            int val = i + 1;
            if (val <= candies) {
                answer[index] += val;
            } else {
                answer[index] += candies;
            }
            candies -= val;
            i++;
        }
        return answer;
    }
}

Solve problem 1103