Pick the K Closest Azure Front Door Edge Sites to a User
Last updated: November 29, 2026
Quick Overview
Given a user's map coordinates and a list of edge sites with coordinates, return the names of the k sites closest to the user by straight-line distance, nearest first.
Microsoft
November 29, 20260
0
0 solved
Given a user's map coordinates and a list of edge sites with coordinates, return the names of the k sites closest to the user by straight-line distance, nearest first.
A top-k heap question in Microsoft phone screens, framed around routing users to Azure Front Door points of presence. The interviewer checks that the candidate uses a bounded max-heap instead of sorting everything and avoids needless square roots.
What the Interviewer Expects
- Compare squared distances to skip sqrt
- Keep a max-heap of size k so the worst kept site is on top
- Replace the top only when a closer site appears
- Return results sorted nearest first
- Mention quickselect as an average O(n) alternative
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
- Sites update their coordinates and health constantly. How would you serve this query at scale?
- Use great-circle distance on latitude and longitude. What changes?
- Return only healthy sites with spare capacity, still the k closest.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
user = (x, y);edges = [(name, x, y), ...].- Output: k names, nearest first; ties broken by name.
- If k exceeds the number of sites, return all....
High-Level Design
Sorting all sites is O(n log n). A max-heap of size k (Python's heapq with negated distances) holds the k best so far; the root is the farthest of them. A new site enters only if it is closer than tha...