Seller Task Scheduler
An e-commerce platform processes tasks submitted by sellers. Tasks arrive one at a time, and the platform repeatedly asks for the next task to process. Implement scheduleSellerTasks(operations), which replays a list of operations and returns one result per process operation.
["receive", taskId, sellerId, tier, priority]queues a task.tieris"VIP"or"STANDARD"and is the same for every task of a seller.priorityis the string"1","2"or"3";"1"is the most urgent.["process"]returns[sellerId, taskId]for the next task, ornullwhen nothing is pending.
Rules
- Within a seller, a lower priority number runs first, and equal priorities run in the order they were received.
- Across sellers, sellers with pending tasks take turns, in the order in which they became non-empty.
- A
STANDARDseller processes one task per turn. AVIPseller processes up to two consecutive tasks per turn. - A seller whose queue empties ends its turn and leaves the rotation. A seller that still has tasks after using its quota moves to the back. A seller that becomes non-empty again later rejoins at the back.
receive a1 A VIP 2 receive a2 A VIP 2 receive a3 A VIP 2 receive b1 B STANDARD 2 receive b2 B STANDARD 2 process x5 -> [A,a1] [A,a2] [B,b1] [A,a3] [B,b2]
Up to 200,000 operations; task ids are unique. Both operations should cost O(1).
Hints
Hint 1
Two structures: per seller, something ordered by (priority, arrival); across sellers, a queue of the sellers that currently have work.
Hint 2
The turn is state, not a loop: remember which seller is mid-turn and how many tasks it may still take, because receive calls can arrive between the two tasks of a VIP turn.
Hint 3
With only three priorities a heap is unnecessary: three FIFO queues per seller, scanned in order, give the next task in constant time.
Topics
Asked at
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.