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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

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
Sliding Window
Two Pointers
Arrays
Counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported