A web app shows toast notifications in a corner, but at most k can be on screen at once. Toast i is requested at time arrivals[i] and stays on screen for durations[i] seconds once it appears.
Toasts appear in request order (first come, first served). Toast i appears at the earliest time t that is at or after its request, at or after the moment the toast before it appeared, and when fewer than k earlier toasts are still on screen. A toast that appeared at time s with duration d is on screen for times s <= t < s + d, so its slot is free again at exactly s + d.
Write toastEnds(arrivals, durations, k) that returns, for each toast, the time it disappears.
Input: arrivals = [0,1,2,3], durations = [5,2,4,1], k = 2 Output: [5,3,7,6]
Toasts 0 and 1 show right away. Toast 2 waits for toast 1 to leave at 3 and shows until 7. Toast 3 waits for toast 0 to leave at 5.
Input: arrivals = [0,0,0], durations = [2,2,2], k = 1 Output: [2,4,6]
Only one toast fits, so each one waits for the one before it.
0 <= arrivals.length <= 10^6 and durations.length === arrivals.lengtharrivals is sorted ascending (ties keep index order).1 <= durations[i] <= 10^6, 0 <= arrivals[i] <= 10^9, 1 <= k <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #12 Toast Notification Timeline. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.