Longest On-Time Delivery Streak If K Late Days Are Excused
Last updated: November 29, 2026
Quick Overview
Given a driver's daily record where 1 means all packages were on time and 0 means at least one was late, return the longest run of consecutive days that would be fully on time if up to k late days were excused.
Amazon
November 29, 20260
0
0 solved
Given a driver's daily record where 1 means all packages were on time and 0 means at least one was late, return the longest run of consecutive days that would be fully on time if up to k late days were excused.
A frequent Amazon online assessment pattern themed on delivery associate performance metrics. The grader checks for a sliding window that tracks the count of zeros and shrinks only when that count exceeds k.
What the Interviewer Expects
- Model the question as the longest window with at most k zeros
- Expand right, increment the zero count on a 0
- Shrink left while zeros exceed k
- Track the best window length
- Handle k = 0 and k >= number of zeros
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the date range of the best streak.
- What if each late day has a different excuse cost and you have a budget?
- How would you answer for many k values at once?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list days of 0s and 1s, integer k >= 0. Output: maximum length of a contiguous subarray containing at most k zeros....
High-Level Design
Maintain a window [left, right] and the number of zeros inside. Each step adds days[right]. If the zero count goes above k, advance left, decrementing the count whenever a zero leaves, until the...