bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 2502. Design Memory Allocator

2502. Design Memory Allocator

Leetcode Solutions

Brute-force Memory Allocation and Deallocation

  1. Initialize an array memory of size n with all elements set to 0.
  2. To allocate memory: a. Iterate through the memory array to find a contiguous block of size free units (value 0). b. If found, set these units to mID and return the starting index of the block. c. If not found, return -1.
  3. To free memory: a. Iterate through the memory array. b. For each unit with value mID, set it to 0 and increment a counter. c. Return the counter value, indicating the number of units freed.
UML Thumbnail

Memory Allocation with Start Index Tracking

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...