104. Tiring Stretch
A nurse tracks the number of hours worked on each day of a long rota; hours[i] is the hours worked on day i. A day is called tiring if more than 8 hours were worked on it, and easy otherwise.
A stretch of consecutive days is a heavy stretch when it has strictly more tiring days than easy days. Return the length, in days, of the longest heavy stretch found in hours. If no heavy stretch exists, return 0. A stretch must contain at least one day.
Example 1
- Input:
- hours = [9,6,10,7,8,10]
- Output:
- 3
- Explanation:
The stretch [9,6,10] has two tiring days and one easy day, and no longer stretch has more tiring than easy days, so the answer is 3.
Example 2
- Input:
- hours = [5,6,8,7]
- Output:
- 0
- Explanation:
There is no tiring day, so no stretch is heavy and the answer is 0.
Constraints
- 1 ≤ hours.length ≤ 106
- 0 ≤ hours[i] ≤ 16
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
- Time per case
- Python 2,000 msC++ 500 msJava 1,000 msJavaScript 1,000 msTypeScript 1,000 ms
Expected complexity
- Time
- O(n)
- Space
- O(n)