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
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
heaps
top-k
quickselect
Azure networking scenario
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported