Longest Green Build Streak if Up to K Failures Can Be Retried
Last updated: November 29, 2026
Quick Overview
A CI history is a list of 1 (passed) and 0 (failed). If you may retry and fix at most k failed builds, return the length of the longest contiguous run that would then be all green.
0
0
0 solved
A CI history is a list of 1 (passed) and 0 (failed). If you may retry and fix at most k failed builds, return the length of the longest contiguous run that would then be all green.
Framed around Google's internal continuous integration dashboards, this is a variable window with a budget constraint. The interviewer checks that the candidate keeps a count of zeros in the window and shrinks only when the budget is exceeded.
What the Interviewer Expects
- Reframes as longest window with at most k zeros
- Tracks zeros inside the window
- Shrinks the left edge only while zeros exceed k
- Handles k = 0 and k larger than total failures
- States O(n) time and O(1) space
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
- What if each failure has a different retry cost and you have a total budget?
- Return the positions of the failures you would retry.
- How would you answer this for many different k values efficiently?
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
buildsof 0s and 1s, integerk >= 0. - Output: the maximum length of a contiguous block containing at most
kzeros....
High-Level Design
Flipping at most k zeros to ones inside a block is the same as asking for the longest block with at most k zeros. Expand right one build at a time, counting zeros. While the count exceeds k, a...