NewThe Learning module is now liveSee what's new

(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 allocate numberOfSlots consecutive free slots. Starting at startIndex, scan positions circularly until a position is found where numberOfSlots consecutive 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 all totalSlots candidate positions, return -1 without modifying storage.
Test Cases
Input
Output
Expected