Medium Accuracy: 53.56%
Submissions: 3625 Points: 4
Given N candies and K people. In the first turn, the first person gets 1 candy, the second gets 2 candies, and so on till K people. In the next turn, the first person gets K+1 candies, the second person gets K+2 candies and so on. If the number of candies is less than the required number of candies at every turn, then the person receives the remaining number of candies. Find the total number of candies every person has at the end.
N = 7, K = 4
1 2 3 1
At the first turn, the fourth person
has to be given 4 candies, but there is
only 1 left, hence he takes only one.
N = 10, K = 3
5 2 3Explanation:
At the second turn first one receives
4 and then we have no more candies left.
You don't need to read input or print anything. Your task is to complete the function distributeCandies() which takes 2 integers N and K as input and returns a list, where the ith integer denotes the number of candies the ith person gets.
Expected Time Complexity: O(logN+K) Expected Auxiliary Space: O(K)