A video player logs the bitrate of each second in rates. A stretch of consecutive seconds is "calm" if its highest and lowest bitrates differ by at most limit.
Write longestCalm(rates, limit) that returns the length of the longest calm stretch. A single second is always calm.
Input: rates = [8,2,4,7], limit = 4 Output: 2
[2, 4] and [4, 7] differ by at most 4; any longer stretch includes a bigger gap.
Input: rates = [10,1,2,4,7,2], limit = 5 Output: 4
[2, 4, 7, 2] has max 7 and min 2, a difference of 5.
1 <= rates.length <= 10^51 <= rates[i] <= 10^90 <= limit <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #273 Longest Calm Stretch. 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.