Debug a driver assignment bug
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates debugging, root-cause analysis, unit/integration test design, observability, and system-resilience competencies within the Coding & Algorithms domain, emphasizing practical skills in reproducing failures, isolating defects, and implementing targeted fixes.
Constraints
- 0 <= len(dashers) <= 200000
- Each dasher is a tuple: (driver_id, distance_meters, last_update_ms, available)
- distance_meters and last_update_ms may be None; such dashers must be ignored
- 0 <= stale_after_seconds <= 10^6
- 0 <= jitter_tolerance_m <= 10^6
Examples
Input: ([(1, 100, 80000, True), (2, 120, 98000, True)], 100000, 30, 5)
Expected Output: 1
Explanation: Dasher 1 is only 20 seconds old, so it is still fresh. The old bug would incorrectly treat 30 seconds as 30 milliseconds. The correct answer is driver 1 because it is clearly closer than driver 2.
Input: ([], 100000, 30, 5)
Expected Output: -1
Explanation: There are no candidates, so no assignment can be made.
Hints
- Be very careful with time units: current_time_ms and last_update_ms are milliseconds, but stale_after_seconds is in seconds.
- You do not need to sort the whole list. First find the minimum valid distance, then scan again to apply the tie-break rules.