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

0

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
sliding window
binary arrays
two pointers
reframing
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported