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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

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
Sliding Window
Two Pointers
Budget Constraint
Binary Arrays
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
  • 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 Problems
Sample Answer
Requirements
  • Input: list builds of 0s and 1s, integer k >= 0.
  • Output: the maximum length of a contiguous block containing at most k zeros....
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...


Submit Your Answer
Markdown supported