Problem · Array
First Five Increasing Temperature Ranges
Learn this problemProblem statement
A stream contains inclusive integer temperature ranges. For a consecutive group of five ranges, you may choose one integer temperature from each range.
Return the earliest zero-based ending index of a five-range group for which the chosen temperatures can be strictly increasing. Return -1 if no such group exists.
Function
firstFiveIncreasingRanges(ranges: int[][]) → intExamples
Example 1
ranges = [[1,2],[2,4],[3,5],[4,8],[5,9]]return = 4The choices 1, 2, 3, 4, 5 form an increasing run ending at index 4.
Example 2
ranges = [[5,5],[4,4],[3,3],[2,2],[1,1],[10,10]]return = -1No five consecutive ranges admit increasing choices.
Constraints
1 <= ranges.length <= 200000- Each row is
[low, high]with-10^9 <= low <= high <= 10^9. - Selections must use five consecutive ranges and one integer from each range.