Distribute Candies to People Problem
Distribute Candies to People Problem — ExecCode Easy DSA Practice
Solve the Distribute Candies to People problem on ExecCode. Free online easy DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given the input needed to solve Distribute Candies to People. Your task is to compute the required answer and return an array (of length numpeople and sum candies) that represents the final distribution of candies. We distribute some number of candies, to a row of n = numpeople people in the following way: We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person. Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and so on until we give 2 n candies to the last person. This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.
Examples
Input {"candies": 7, "numpeople": 4}; Output [1, 2, 3, 1]. Input {"candies": 10, "numpeople": 3}; Output [5, 2, 3]
Constraints
1 <= candies <= 10^9 1 <= num_people <= 1000
Practice Distribute Candies to People free on ExecCode. Browse DSA problems, topic map, and placement guides.