Suppose there are words given. These are first and second, consider occurrences in some text of the form "first second third", here second comes immediately after the first, and third comes immediately after the second.
For each such cases, add "third" into the answer, and show the answer. So if the text is like “lina is a good girl she is a good singer”, first = “a”, second = “good”, the answer will be [girl, singer]
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution(object): def distributeCandies(self, candies, num_people): """ :type candies: int :type num_people: int :rtype: List[int] """ res = [0 for i in range(num_people)] index = 0 while candies>0: res[index%num_people] += min(candies,index+1) candies-=(index+1) index+=1 return res
"lina is a good girl she is a good singer" "a" "good"