← 返回 doordash 的题目列表Dasher Picker
类型:online_judge
Implement a Dasher Picker system. The system consists of two functions: addDasher and pickDasher.
addDasher: Adds a new dasher identifier to a set. Assume the initial set is {0, 1, 2}, after one call of addDasher, the set becomes {0, 1, 2, 3}.
pickDasher: Randomly selects a dasher identifier from the set and removes it. Then adjust the values in the set to ensure continuity. For example, if the initial set is {0, 1, 2, 3}, and pickKey returns 1, the set becomes {0, 2, 3}, then adjusts to {0, 1, 2}.
Consider how to optimize the code, ensure thread safety, and provide solutions for when the service restarts and the set is cleared.
Example
Input
addDasher
pickDasher
addDasher
pickDasher