Select the best dasher for an order
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This problem evaluates algorithmic selection and geometric computation skills—filtering eligible dashers, calculating Euclidean distances, and applying deterministic tie-breaking—within the Coding & Algorithms domain at an implementation-level algorithmic abstraction.
Constraints
- 0 <= len(dashers) <= 100000
- -1000000 <= x, y <= 1000000
- Each dasher is represented as `(id, x, y, is_available)`
- Dasher ids are unique integers
Examples
Input: ((3, 4), [(1, 0, 0, True), (2, 2, 2, True), (3, 10, 10, False)])
Expected Output: 2
Explanation: Available dashers are 1 and 2. Their squared distances to (3, 4) are 25 and 5, so dasher 2 is the closest.
Input: ((0, 0), [(5, 3, 4, True), (2, -3, -4, True), (8, 1, 1, False)])
Expected Output: 2
Explanation: Dashers 5 and 2 are both available and both have squared distance 25 from the pickup point. The tie is broken by smaller id, so return 2.
Input: ((1, 1), [(10, 0, 0, False), (11, 2, 2, False)])
Expected Output: None
Explanation: No dashers are available, so the result is None.
Input: ((7, -2), [])
Expected Output: None
Explanation: The dasher list is empty, so there is no eligible dasher.
Input: ((-1, -1), [(7, -1, -1, True)])
Expected Output: 7
Explanation: The only dasher is available and already at the pickup location, so return id 7.
Hints
- You do not need to compute the actual square root for Euclidean distance. Comparing squared distances gives the same ordering.
- Track the current best available dasher while scanning the list once, and apply the id tie-break rule when distances are equal.