(This question is a variation of the LeetCode question 2502. Design Memory Allocator. If you haven't completed that question yet, it is recommended to solve it first.)
You are given a circular storage system with totalSlots slots indexed 0 through totalSlots - 1, all initially empty. Given an array of requests, process them in order and return one integer result per request.
Each request is an array of 3 strings. Two request types are supported:
- Store:
["store", "<startIndex>", "<numberOfSlots>"]: Attempts to allocatenumberOfSlotsconsecutive free slots. Starting atstartIndex, scan positions circularly until a position is found wherenumberOfSlotsconsecutive circular slots are all free. If found, mark those slots as used and return the actual starting index. If no valid position exists after checking alltotalSlotscandidate positions, return-1without modifying storage.
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
Output
Expected