← 返回 doordash 的题目列表Code Craft: Dasher Pay via Mock Service API
类型:qbank
Variant of the Dasher Pay round in which the dasher's order data is exposed by a mock service. The candidate must call the service, compute pay, and (mid-round) be told to also write a mock API wrapper around the underlying function. Tests whether the candidate can keep the algorithmic core decoupled from the API plumbing.
Requirements
Input: a mock DasherService that takes a dasher ID and returns the list of completed order intervals (start, end).
Compute the dasher's pay given a per-minute wage rate.
Mid-round, the interviewer asks the candidate to wrap the function call in an API mock — essentially, define a small client class that calls the service and returns the computed pay.
Follow-up: if a dasher accepts multiple overlapping orders, do not double-count time — bill for the actual elapsed time, not the sum of per-order durations.
Notes
Two-layer structure:
Core algorithm: take a list of intervals and a rate; return total pay. Use interval-merge or sweep to compute total elapsed time without double-counting.
API wrapper: a thin class with a getPay(dasher_id) method that calls DasherService.fetchOrders(dasher_id), runs the core algorithm, and returns the result.
Keep the core pure; do not pass the API client into the algorithm function. This is exactly what the interviewer is grading when they bring up the API mock mid-round.
The overlap follow-up is the source of the round's reported friction — one candidate was told a double-counted result was wrong, then told the corrected single-count was also wrong. Be ready to defend the interval-merge logic with a worked example.
Interval-merge: sort intervals by start, sweep to compute total covered length.
Edge cases: empty order list (pay = 0), zero-length orders, orders that are subsets of one another.
Preparation
Drill the interval-merge / covered-length pattern (LC 56 "Merge Intervals" + total-covered-length variant).
Practice writing a small API wrapper class in 5 minutes that decouples the algorithm from the data source.
Have a worked example ready showing why double-counted time is wrong (two orders overlapping for 10 minutes should bill for 10 minutes of wage, not 20).