Circular Server Scheduling with Recovery
Problem statement
Servers 0 through serverCount - 1 are cyclic. Command index is its time. Maintain a pointer initially before server 0.
REQUESTscans cyclically after the pointer for the first server available at this time. That server processes the request and becomes the pointer. If none is available, drop the request.- After a server processes
workLimitrequests since its last wake, it is unavailable for the nextrecoveryTimecommand times; its work counter resets when recovery finishes. UP iimmediately makes server i available and resets its work counter; the pointer does not move.
Return the smallest server ID among those processing the most requests.
Function
busiestServer(serverCount: int, workLimit: int, recoveryTime: int, commands: String[]) → intExamples
Example 1
serverCount = 3workLimit = 5recoveryTime = 2commands = ["REQUEST","REQUEST","REQUEST","REQUEST"]return = 0Available servers receive requests cyclically.
Example 2
serverCount = 2workLimit = 1recoveryTime = 2commands = ["REQUEST","REQUEST","REQUEST","REQUEST"]return = 0Servers become available after their recovery windows.
Constraints
1 <= serverCount, workLimit <= 10000 <= recoveryTime <= 1000001 <= commands.length <= 100000