AlgoMaster Logo
AlgoMasterEnforce Bulkhead Pool Admissionmedium

Enforce Bulkhead Pool Admission

medium

The bulkhead pattern partitions a service's resources so overload in one dependency or tenant cannot consume capacity reserved for another. Each compartment has its own limit and fills independently.

Design a BulkheadAdmissionController class:

  • BulkheadAdmissionController() creates a stateless controller.
  • boolean[] admit(int[] capacities, int[] requests) returns the admission decision for every request in chronological order.

capacities[p] is the number of slots in pool p. Each value in requests is the index of the pool targeted by that request.

For each request:

  • Return true and occupy one slot when the target pool still has capacity.
  • Return false when the target pool is already full.

An admitted request remains active for the rest of that simulation; there are no releases. A rejected request consumes no slot. Pools never share or borrow capacity, even when another pool has unused slots. Each call to admit is a new simulation and must not retain occupancy from an earlier call.

Example 1:

Input:

Output:

Explanation: Pool 0 admits its first two requests and then rejects its third. Pool 1 has a separate budget, so it also admits its first two requests before rejecting its third.

Example 2:

Input:

Output:

Explanation: The first three requests fill pool 1. Pool 0 is unaffected and still admits one request before reaching its own capacity of 1.

Constraints

  • 1 <= capacities.length <= 100
  • 0 <= capacities[p] <= 10^6
  • 0 <= requests.length <= 10^5
  • 0 <= requests[i] < capacities.length
  • Requests are processed in the given order.
  • At most 100 calls are made to admit.
Hints

Loading...
CallReturns
new BulkheadAdmissionController()null
admit([2,2], [0,0,1,0,1,1])[true,true,true,false,true,false]

Pool 0 admits its first two requests and rejects its third. Pool 1 independently admits its first two requests and rejects its third.

Run checks these cases. Submit also runs a larger hidden set.