Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-203

Arena Bump Allocation Pointer

Problem

Simulate a bump-pointer arena allocator.

size is the total arena size and operations is a list of integers: a non-negative value requests that many bytes at the current pointer, and -1 resets the arena. An allocation that does not fit fails without moving the pointer.

Return the start offset for each allocation, None for each reset, or -1 when an allocation fails.

Hint

A failed allocation leaves the bump pointer unchanged.

Test cases

case 1
in: [10,[3,4,3,0,1]]
expected: [0,3,7,10,-1]
case 2
in: [8,[-1,5,5]]
expected: [null,0,-1]
case 3
in: [0,[1]]
expected: [-1]
case 4
in: [5,[2,-1,4]]
expected: [0,null,0]
Starter codePython
def arena_bump(size, operations):
    # Your code here
    pass

4 test cases · run your code against them in the editor