Minimum Size Subarray Sum
Real-world version: Fewest Shifts to Clear the QuotaThe statement here is our own: the same inputs, outputs and technique.
A field engineer logs the hours worked on each day of a tour, day by day, in hours.
Payroll wants to credit one unbroken run of days whose logged hours add up to quota or more, and it wants that run to cover as few days as it can. The run has to be consecutive days: skipping a day inside it is not allowed.
Return the number of days in the shortest qualifying run. When no run of consecutive days reaches quota, return 0.
Examples
Example 1
- Input
- quota = 11, hours = [4, 2, 5, 1, 6, 3]
- Output
- 3
The days logging 5, 1 and 6 add up to 12, which clears the quota with three days. No pair of neighbouring days gets past 9, so two days are never enough.
Example 2
- Input
- quota = 10, hours = [1, 1, 10]
- Output
- 1
The final day alone logs 10 and clears the quota, so a single day is the shortest run even though the whole tour also qualifies.
Example 3
- Input
- quota = 100, hours = [1, 2, 3]
- Output
- 0
The entire tour logs only 6 hours, so no run can reach 100 and the answer falls back to 0.
Constraints
- 1 <= quota <= 10^9
- 1 <= hours.length <= 10^5
- 1 <= hours[i] <= 10^4
- Return 0 when no run of consecutive days reaches quota
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def fewest_shifts_for_quota(quota: int, hours: list[int]) -> int:public int fewestShiftsForQuota(int quota, int[] hours)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Max Consecutive Ones IIIReal-world version: Longest Verified Backup StreakMedium
- Subarray Product Less Than KReal-world version: Safe Stretches of the Filter CascadeMedium
- Frequency of the Most Frequent ElementReal-world version: Plates at One ThicknessMedium
- Minimum Operations to Reduce X to ZeroReal-world version: Loading Crates From Both EndsMedium