Circular Memory Slot Allocator
Updated
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.
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Stabilize Student Test ScoresVirtu Financial · OAVirtu Financial interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Index of the Maximum After Left RotationsChubb · OAChubb interview questions
- Leaves Remaining After WindCresta · OACresta interview questions
- Rolling MetricsAkuna Capital · OAAkuna Capital interview questions