Chat agent assignment

Write codeMedium26 min

Your task

A support desk staffs agent_count agents numbered from 0, and there is always at least one. Each entry of ops is either 'open 7' or 'close 7', where the number names one chat. An open hands the chat to whichever agent is carrying the fewest open chats right now, and a tie goes to the lowest agent number. A close ends that chat, so the agent carrying it drops one. A close naming a chat that is not currently open is ignored, and a chat is never opened twice while it is open. Return the agent number that took each open, in the order the opens appear. Return an empty list when no chat is ever opened.

Examples

chat_desk_routing(agent_count: int, ops: list[str]) -> list[int]
Example 1
Inputchat_desk_routing(2, ["open 1", "open 2", "open 3", "close 1", "open 4"])
Output[0, 1, 0, 0]
Example 2
Inputchat_desk_routing(3, ["open 9", "open 8", "close 9", "open 7"])
Output[0, 1, 0]
Example 3
Inputchat_desk_routing(2, ["open 1", "open 2", "close 2", "close 1", "open 3", "open 4"])
Output[0, 1, 0, 1]