Circular Memory Slot Allocator
Problem statement
Memory contains totalSlots slots in a circle. Each request is [kind,start,length].
Savescans candidate starts cyclically beginning at start and finds the first run of length consecutive free slots, allowing the run to wrap. Occupy it and return its starting slot, or return -1 without mutation.Clearfrees the guaranteed-occupied circular run beginning at start and returns length.
Return one result per request.
Function
processMemoryRequests(totalSlots: int, requests: String[][]) → int[]Examples
Example 1
totalSlots = 5requests = [["Save","1","2"],["Save","1","2"],["Clear","1","2"],["Save","1","2"]]return = [1,3,2,1]Allocation, first-fit movement, clearing, and reuse are exercised.
Example 2
totalSlots = 5requests = [["Save","4","2"]]return = [4]A run may wrap from the final slot to zero.
Constraints
1 <= totalSlots <= 10001 <= requests.length <= 100000- Every length is between 1 and totalSlots.