FastPrepCircular Server Scheduling with Recovery

Circular Server Scheduling with Recovery

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

Servers 0 through serverCount - 1 are cyclic. Command index is its time. Maintain a pointer initially before server 0.

  • REQUEST scans 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 workLimit requests since its last wake, it is unavailable for the next recoveryTime command times; its work counter resets when recovery finishes.
  • UP i immediately 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[]) → int

Examples

Example 1

serverCount = 3workLimit = 5recoveryTime = 2commands = ["REQUEST","REQUEST","REQUEST","REQUEST"]return = 0

Available servers receive requests cyclically.

Example 2

serverCount = 2workLimit = 1recoveryTime = 2commands = ["REQUEST","REQUEST","REQUEST","REQUEST"]return = 0

Servers become available after their recovery windows.

Constraints

  • 1 <= serverCount, workLimit <= 1000
  • 0 <= recoveryTime <= 100000
  • 1 <= commands.length <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int busiestServer(int serverCount, int workLimit, int recoveryTime, String[] commands) {
    // Write your code here.
}
serverCount3
workLimit5
recoveryTime2
commands["REQUEST","REQUEST","REQUEST","REQUEST"]
expected0
Checking account…