An editor autosaves with a debounce of wait ms, but during non-stop typing it must still save at least every maxWait ms. The rules:
burstStart.Math.min(time + wait, burstStart + maxWait).If a call happens at exactly the time a save is due, the save happens first. Write debounceMaxWait(calls, wait, maxWait) that returns the save times in order. calls is sorted ascending.
Input: calls = [0,100,200,300,400,500], wait = 150, maxWait = 350 Output: [350,650]
The burst starts at 0, so saves can't wait past 350. The call at 400 starts a new burst, and the last call at 500 sets the save to 650.
Input: calls = [0,1000], wait = 100, maxWait = 500 Output: [100,1100]
Calls far apart behave like a plain debounce.
0 <= calls.length <= 2 * 10^50 <= calls[i] <= 10^9, sorted ascending.1 <= wait <= maxWait <= 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 #722 Debounce with a Maximum Wait. 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.