Shortest Run of Builds Whose Total Minutes Reach a Budget

Last updated: November 29, 2026

Quick Overview

Given an array of positive build durations in minutes from an Azure Pipelines agent and a target T, return the length of the shortest contiguous run of builds whose total duration is at least T, or 0 if none exists.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given an array of positive build durations in minutes from an Azure Pipelines agent and a target T, return the length of the shortest contiguous run of builds whose total duration is at least T, or 0 if none exists.

An approachable sliding window problem for Microsoft phone screens, set in Azure Pipelines capacity planning. Because all durations are positive, the interviewer expects a two pointer window and may ask why that would break with negatives.

What the Interviewer Expects
  • Note that positive values make the window sum monotonic
  • Expand right and shrink left while the sum meets the target
  • Record the minimum length at each shrink
  • Return 0 when no window qualifies
  • Contrast with the prefix sum plus binary search alternative
Key Topics to Cover
sliding window
two pointers
arrays
monotonicity
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 durations can be zero or negative?
  • Can you solve it in O(n log n) with prefix sums and binary search?
  • How would you report every minimal window, not just the length?
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 durations of positive integers and integer T > 0. Output: minimal length of a contiguous subarray with sum >= T, or 0. Because values are strictly positive, extending a window always i...

High-Level Design

Maintain a window [left, right] and its running sum. For each new right, add its duration. While the sum is at least T, the window is valid, so record its length, then subtract durations[left] a...


Submit Your Answer
Markdown supported