DoorDash OA Interview Question: Debugging Dasher Picking for Deliveries

14 Views
No Comments

Debugging: Dasher Picking for Deliveries

Description

We have some code that attempts to assign a random dasher to a delivery:

  • There is a class Dasher that inherits from class User. All the users have a property id which is unique in the system, so let’s assume that there are no duplicated ids in Dasher objects.
  • There is a service DeliveryAssignmentService that hosts the dasher assignment logic.
    • The method addDasher can be called to add an available dasher to the system.
    • The field dasherMap contains all the dashers. The keys are consecutively increasing numbers starting from 0, which will be used for the method pickDasher() to pick a random Dasher object.
    • The method pickDasher will return a random dasher for the next delivery. The private method pickKey() will call object Random’s function nextInt() to get a random key from the consecutive key series. When a key is picked, the entry will be removed, and in the private method adjustMap() the map will move its largest key to fill the gap so that the keys are still consecutive from 0.
    • There is a remote service RemoteDeliveryRecordingService to be called when dasher adding or dasher picking happens.
    • The main() method gives you an example of how the code would be called.

However, unfortunately this code has logic bugs, bad designs, as well as some bad practices. Please try to find as many as you can, and then fix them. Logic bugs are more important as by fixing them we would have working code.

All the problems mentioned above are NOT language specific, so please do not worry about lacking knowledge of a specific language.

This problem asks you to debug a random-assignment service that stores dashers in a map with consecutive integer keys. The main challenge is to keep the keys compact after removing a randomly picked dasher, so the implementation must correctly handle random index generation, deletion, and map rebalancing. In addition to logic bugs, the code also contains design and maintainability issues such as improper initialization, weak separation of concerns, and unsafe handling of empty collections.

END
 0