Instacart·Software Engineer·Technical Phone Screen
- You're building a last-mile delivery simulator with a single shopper. Given n orders each with an arrival time and a service time, the shopper processes one order at a time and is idle until the next one arrives. Compute the average waiting time across all customers, where waiting time is finish time minus arrival time. Return a float rounded to 5 decimal places.
- Follow-up: extend the simulator to k shoppers (k >= 1). Orders must be processed strictly in arrival order and each new order goes to whichever shopper is free earliest, breaking ties by smallest shopper ID. Compute the average waiting time and analyze the time and space complexity of your solution.
“The single-shopper version is pretty mechanical once you track when the shopper becomes free.”