A server log has the times (in seconds) of every request in times, in no particular order. The on-call dashboard wants the widest quiet period: the biggest difference between two requests that are next to each other once the times are sorted.
Write widestGap(times) that returns that difference, or 0 if there are fewer than two requests. Aim for linear time: you can find the widest gap without sorting the times.
Input: times = [3,6,9,1] Output: 3
Sorted: 1, 3, 6, 9. The gaps are 2, 3, and 3.
Input: times = [10] Output: 0
One request has no neighbor.
0 <= times.length <= 1000000 <= times[i] <= 10^9Run 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 #207 Widest Quiet Period. 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.