Weighted Round-Robin Seller Task Scheduler
Learn this problemProblem statement
Simulate a seller task scheduler over a finite sequence of RECEIVE and PROCESS operations. A receive supplies a unique task ID, seller ID, fixed seller tier (VIP or STANDARD), and priority from 1 through 3.
Within one seller, smaller priority numbers are processed first and equal priorities are FIFO. Active sellers rotate in first-activation round-robin order. A VIP seller may process up to two tasks in one turn; a standard seller may process one. A seller whose turn quota expires while work remains moves to the back. A seller whose queue becomes empty leaves the rotation and rejoins at the back if new work arrives.
For each PROCESS, return sellerId:taskId, or the empty string if no task is waiting. Fields paired with PROCESS are ignored.
Function
scheduleSellerTasks(operations: String[], taskIds: String[], sellerIds: String[], sellerTiers: String[], priorities: int[]) → String[]Examples
Example 1
operations = ["RECEIVE","RECEIVE","RECEIVE","RECEIVE","PROCESS","PROCESS","PROCESS","PROCESS"]taskIds = ["v1","v2","v3","s1","","","",""]sellerIds = ["V","V","V","S","","","",""]sellerTiers = ["VIP","VIP","VIP","STANDARD","","","",""]priorities = [1,2,3,1,0,0,0,0]return = ["V:v1","V:v2","S:s1","V:v3"]The VIP seller receives two consecutive dispatches, the standard seller receives one, then the VIP seller returns.
Example 2
operations = ["RECEIVE","RECEIVE","RECEIVE","RECEIVE","PROCESS","PROCESS","PROCESS","PROCESS"]taskIds = ["a1","a2","b1","b2","","","",""]sellerIds = ["A","A","B","B","","","",""]sellerTiers = ["STANDARD","STANDARD","STANDARD","STANDARD","","","",""]priorities = [1,1,1,1,0,0,0,0]return = ["A:a1","B:b1","A:a2","B:b2"]Two standard sellers alternate until both queues are empty.
Constraints
1 <= operations.length <= 100000; all five arrays have equal length.- Each operation is
RECEIVEorPROCESS. - Each receive uses a globally unique nonempty task ID, a nonempty seller ID, a tier of
VIPorSTANDARD, and priority1,2, or3. - Every receive for the same seller uses the same tier.
- The combined length of all task and seller IDs is at most
500000.