Longest Well-Performing Interval - Problem
We are given hours, a list of the number of hours worked per day for a given employee.
A day is considered to be a tiring day if and only if the number of hours worked is strictly greater than 8.
A well-performing interval is an interval of days for which the number of tiring days is strictly larger than the number of non-tiring days.
Return the length of the longest well-performing interval.
Input & Output
Example 1 — Basic Well-Performing Interval
$
Input:
hours = [9,9,6,0,6,6,9]
›
Output:
3
💡 Note:
The longest well-performing interval is [9,9,6] from index 0 to 2. It has 2 tiring days (9>8, 9>8) and 1 non-tiring day (6≤8), so tiring > non-tiring.
Example 2 — No Well-Performing Interval
$
Input:
hours = [6,6,6]
›
Output:
0
💡 Note:
All days have ≤8 hours, so no interval can have more tiring days than non-tiring days. The longest well-performing interval has length 0.
Example 3 — Entire Array is Well-Performing
$
Input:
hours = [9,9,9]
›
Output:
3
💡 Note:
All days are tiring (>8 hours), so the entire array [9,9,9] is well-performing with 3 tiring days and 0 non-tiring days.
Constraints
- 1 ≤ hours.length ≤ 104
- 0 ≤ hours[i] ≤ 16
Visualization
Tap to expand
Understanding the Visualization
1
Input Analysis
Classify each day as tiring (>8 hours) or non-tiring (≤8 hours)
2
Interval Search
Find intervals where tiring days > non-tiring days
3
Maximum Length
Return length of longest well-performing interval
Key Takeaway
🎯 Key Insight: Transform to +1/-1 scoring system and find longest positive-sum subarray
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code