Distribute N Candies Among K People
Explanation: Sanyam wishes to distribute 'N' candies among 'K' friends. The friends are arranged based on Sanyam's order of likeness. He initially distributes candies such that the 1st friend receives 1 candy, the 2nd friend receives 2 candies, up to the kth friend. In the subsequent rounds, the distribution is incremented by 'K' starting from the 1st friend. If during distribution, the remaining candies are fewer than what a friend is supposed to receive, that friend receives all remaining candies and the process stops.
Input:T
test cases will follow. Each test case contains two integers,N
andK
whereN
is the number of candies andK
is the number of friends.
Output: For each test case, output the number of candies each friend ends up with at the end of the distribution.
Example:
Input:
T = 1
N = 10
K = 3
Output:
[5, 2, 3]
Explanation:
In this example, the distribution is as follows:
- First, [1, 2, 3] are distributed.
- Second, [4, 5] are distributed and the process stops because there are 2 candies left, only enough for two friends.
Constraints:
1 <= T <= 50
1 <= N <= 10^9
1 <= K <= 10^5
Time Limit: 1 second
Top GeeksForGeeks Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in GeeksForGeeks Software Developer
Reviews
Interviews
Salaries
Users/Month