Place Edge Caches to Maximize the Minimum Spacing Between Them
Last updated: November 29, 2026
Quick Overview
Along a fiber route there are candidate positions (in kilometers) where Azure CDN caches can be installed. Place m caches at distinct candidate positions so the smallest distance between any two caches is as large as possible.
Microsoft
November 29, 20260
0
0 solved
Along a fiber route there are candidate positions (in kilometers) where Azure CDN caches can be installed. Place m caches at distinct candidate positions so the smallest distance between any two caches is as large as possible.
A maximize-the-minimum problem that Microsoft onsite interviewers use to check binary search on answer when the predicate goes the other way. Getting the upper-mid and bound updates right is part of the test.
What the Interviewer Expects
- Sort the positions
- Feasibility: can we place m caches with every gap at least g?
- Greedy placement at the earliest valid spot is optimal for a fixed g
- Binary search for the largest feasible g with an upper mid
- Discuss why the predicate is monotone
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
- Return the chosen positions too.
- Positions are real numbers. How do you terminate?
- Some positions cost more to use; maximize spacing subject to a budget.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
positions: distinct integers, unsorted.2 <= caches <= len(positions).- Output: the largest achievable minimum gap....
High-Level Design
If a gap g is achievable, every smaller gap is too, so feasibility flips from True to False once. For a fixed g, placing the first cache at the leftmost position and every next one at the first positi...