Ctrl K

Hard Shifts Take the Lead

Medium
The array shifts is an employee's work log: shifts[i] is how many hours they worked on day i. A day is hard if they worked strictly more than 8 hours; otherwise it is light. Find the longest run of consecutive days in which hard days strictly outnumber light ones. Return the length of that run, or 0 if no such run exists.
Example 1
shifts=[10, 4, 12, 11, 3, 2, 7] → 5

The first five days [10, 4, 12, 11, 3] hold three hard days and two light ones. No longer stretch has more hard days than light ones.

Example 2
shifts=[8, 5, 8] → 0

Exactly 8 hours is not yet a hard day, so there are no hard days at all and the answer is 0.

Example 3
shifts=[9, 0, 9, 0, 9] → 5

The whole period works: three hard days against two light ones.

Constraints
  • 1 ≤ len(shifts) ≤ 10⁴
  • 0 ≤ shifts[i] ≤ 16
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWeakest Link Times Total MediumNext Larger on the Right EasyWeakest-Link Crew Power HardPreorder of a Search Tree MediumLongest Run with a Given Sum Medium
loading Python…
Input
shifts=[10, 4, 12, 11, 3, 2, 7]
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 102 tests on the server, hidden ones included.