Count Later Builds With Lower Latency for Every Build

Last updated: November 29, 2026

Quick Overview

Given end-to-end latencies for a sequence of Azure DevOps builds, return for each build how many later builds had strictly lower latency.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given end-to-end latencies for a sequence of Azure DevOps builds, return for each build how many later builds had strictly lower latency.

A counting-inversions problem in Microsoft onsite style. The interviewer expects the O(n^2) baseline, then an O(n log n) solution with a Fenwick tree over compressed values or a merge sort that tracks counts, and a clear argument about duplicates.

What the Interviewer Expects
  • Start with the O(n^2) double loop
  • Process builds right to left so the structure holds only later builds
  • Compress latencies to ranks so the Fenwick tree stays small
  • Query strictly smaller ranks, then insert the current one
  • Mention merge sort as an alternative
Key Topics to Cover
ordered sets
Fenwick tree
coordinate compression
inversions
merge sort
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
  • Count later builds with higher latency instead.
  • Return the total number of inversions in one number. Which method is simplest?
  • Values stream in and you must answer for each new build how many earlier builds were slower.
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 numbers (duplicates allowed).
  • Output: list where out[i] = number of j > i with latency[j] < latency[i]....
High-Level Design

Walk from the right. At position i, everything already inserted lies to the right of i, so the answer is the number of inserted values strictly smaller than latency[i]. A Fenwick tree (binary indexed ...


Submit Your Answer
Markdown supported