Top K Highest Rated Restaurants Within a Delivery Radius

Last updated: November 29, 2026

Quick Overview

Given restaurants as (id, x, y, rating) and a customer location, return the ids of the k highest rated restaurants within a delivery radius, breaking ties by shorter distance and then by smaller id.

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

0

0

0 solved


Given restaurants as (id, x, y, rating) and a customer location, return the ids of the k highest rated restaurants within a delivery radius, breaking ties by shorter distance and then by smaller id.

A heap question rooted in the DoorDash home feed, where the app must surface a short, well-ordered list of nearby stores. The interviewer checks that you filter before ranking, keep a size-k min-heap instead of sorting everything, and write a tie-break key that is fully deterministic.

What the Interviewer Expects
  • Filter by radius before any ranking work
  • Use a min-heap of size k so the weakest kept candidate is on top
  • Encode the three-level tie break in one comparable key
  • Return results best first
  • Compare O(n log k) with O(n log n) sorting
Key Topics to Cover
heaps
top-k selection
tie breaking
geospatial filtering
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
  • How would you rank by a blend of rating, distance and predicted ETA?
  • What if the restaurants are already indexed in a geohash or quadtree?
  • How would you paginate to fetch the next k?
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: restaurants with integer ids, customer point (cx, cy), radius, and k.
  • Keep only restaurants with Euclidean distance <= radius.
  • Order: rating descending, then distance ascending,...
High-Level Design

Build a key where a larger key means a better restaurant: (rating, -distance, -id). Python tuples compare left to right, so this captures all three tie breaks. Maintain a min-heap of at most k entri...


Submit Your Answer
Markdown supported