Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Match Drivers to Restaurants
00:00
5 left

Match Drivers to Restaurants

MediumPython

Problem

Given an array of delivery coordinates, write an algorithm to find the closest driver-restaurant pairs within a specific threshold. Use Euclidean distance and include every driver-restaurant pair whose distance is less than or equal to the threshold. The function accepts drivers, restaurants, and threshold, and returns pairs as [driver_index, restaurant_index], ordered by ascending distance, then driver index, then restaurant index.

Constraints

  • 0 <= len(drivers), len(restaurants) <= 1000
  • Each coordinate is a pair [x, y]
  • -10^9 <= x, y <= 10^9
  • 0 <= threshold <= 10^9
  • Return every qualifying pair, not only one pair per driver
  • Order results by ascending distance, then driver index, then restaurant index

Function Signature

def find_closest_pairs(drivers, restaurants, threshold):
Interviewer

Your question is Match Drivers to Restaurants. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.