A sticky header updates on scroll, but at most once every wait milliseconds. The handler runs immediately on a scroll event if at least wait ms have passed since it last ran (or if it has never run); otherwise that event is ignored.
Write throttleRuns(calls, wait) where calls holds the scroll event times, sorted ascending. Return the times at which the handler runs.
Input: calls = [0,100,250,600], wait = 200 Output: [0,250,600]
100 is only 100 ms after the run at 0, so it is ignored; 250 is 250 ms later, so it runs.
Input: calls = [0,16,32,48,64], wait = 32 Output: [0,32,64]
Exactly wait ms later counts as enough.
0 <= calls.length <= 2 * 10^50 <= calls[i] <= 10^9, sorted ascending.1 <= wait <= 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 #720 Throttled Scroll Handler. 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.