Longest Green Build Streak After Retrying At Most K Failures
Last updated: November 29, 2026
Quick Overview
Given a binary array of CI results (1 for pass, 0 for fail) and an integer k, return the length of the longest contiguous run of passes you can get if you are allowed to retry and turn at most k failures into passes.
Microsoft
November 29, 20260
0
0 solved
Given a binary array of CI results (1 for pass, 0 for fail) and an integer k, return the length of the longest contiguous run of passes you can get if you are allowed to retry and turn at most k failures into passes.
Appears on Microsoft online assessments with a DevOps reliability framing. The interviewer checks that you can rephrase the goal as the longest window with at most k zeros and implement it without nested scanning.
What the Interviewer Expects
- Reframe as longest window containing at most k zeros
- Count zeros inside the window
- Shrink left when zeros exceed k
- Return the best window length
- Explain the non-shrinking window variant as an optimization
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
- How would you return which failures to retry?
- What if each retry has a different cost and you have a budget?
- How does this change if results arrive as a stream?
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 of 0s and 1s, integer k >= 0. Output: longest length of a contiguous subarray containing at most k zeros. With k = 0 this is just the longest run of 1s....
High-Level Design
Slide a window and count zeros in it. Extend right; if the new element is 0, increment zeros. While zeros > k, move left forward, decrementing zeros when a 0 leaves. Every window after the i...