A smart-home dashboard highlights the longest stretch of readings where the temperature stayed steady: the highest and lowest reading in the stretch differ by at most tolerance.
Write longestSteady(readings, tolerance) that returns the length of the longest run of neighboring readings whose maximum minus minimum is at most tolerance. Return 0 for an empty list.
Input: readings = [8,2,4,7], tolerance = 4 Output: 2
[2, 4] and [4, 7] stay within 4; any run of three spans at least 5.
Input: readings = [10,1,2,4,7,2], tolerance = 5 Output: 4
[2, 4, 7, 2] ranges from 2 to 7.
0 <= readings.length <= 100000-10^4 <= readings[i] <= 10^40 <= tolerance <= 10^4Run 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 #139 Longest Steady Temperature 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.