Doordash | Phone Screen | Software Engineer E4 | Closest Drivers to Restaurant

Question
Given a restaurant geolocation ( longitude / latitude), find 3 closest Dashers (drivers) near the restaurant who can be assigned for delivery, ordered by their distance from the restaurant. In case 2 Dashers are equidistant from the restraunt, use Dasher rating as tie breaker.

Each Dasher has 3 properties:

  1. Dasher ID
  2. Last known location [x,y]
  3. Rating (0 - 100). Higher the better

Assume you have a method GetDashers() which returns a list of all Dashers.

Input
Restaurant Location

Output
List of 3 nearest Dasher IDs. Example: [11, 14, 17]

Assume GetDashers() returns a List<Dasher> where Dasher is represented by:

class Dasher {
    long id;
    Location lastLocation
    int rating;
    
    public Dasher(long id, Location lastLocation, int rating) {
        this.id = id;
        this.lastLocation = lastLocation;
        this.rating = rating;
    }
}

and Location is represented by:

class Location {
    double longitude;
    double lattitude;
    
    Location(double longitude, double lattitude) {
        this.longitude = longitude;
        this.lattitude = lattitude;
    }
}
Comments (14)