Sending notifications in batches
Write code · Challenge · §8.3 Guessing the answer and checking it
subs holds the subscriber count of each person who uploaded a new post, in the order they uploaded. Each of an uploader's subscribers gets one new-post notification, and the notification server sends one batch of notifications once a minute. If the batch limit is set to m, each batch keeps adding the notifications for the next person in the order of subs while its total stays at most m; the first person who does not fit starts the next batch. The notifications for one uploader (as many as that person's subscribers) are never split; they all go in the same batch.
Complete the function solution, which returns the smallest m with which all notifications are sent within d minutes (in at most d batches).
Function
solution(subs, d)
Constraints
- The length of
subsis from 1 to 10,000. - Each element of
subsis an integer from 1 to 100,000. dis an integer from 1 to 10,000.
Examples
| subs | d | result |
|---|---|---|
[25, 50, 25, 20, 25, 40] | 3 | 75 |
[20, 60, 60, 45, 20] | 2 | 125 |
Starter code
def solution(subs, d):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.