Reported September 2026
SIGsimulation

Leftmost Memory Block Allocator

Reported by candidates from SIG's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live SIG OA. Under 2s to a working solution.
Founder's read

SIG put this one in front of candidates in September 2026, and it looks like a design problem but it's really a simulation. You get a 0/1 memory array and up to 1000 queries. Allocate the leftmost run of x free cells, or erase a block by ID. The constraints are small, so nothing fancy is required. If you're taking this OA in the next day or two, the win is staying clean on the bookkeeping. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is very doable on your own.

The problem

You are given an integer array memory containing only 0s and 1s. A value of 0 means that the memory unit is free, while 1 means that it is occupied.
Process the two-element arrays in queries in order. Each query has one of two forms:
[0, x] is an allocation query. Find the smallest index that begins a contiguous block of x free units. If a block exists, mark all of its units as occupied, assign the next allocation ID to the block, and return its starting index. Allocation IDs start at 1 and increase only after successful allocations. If no block fits, return -1.
[1, id] is an erase query. If an active allocation has ID id, free every unit in that block and return its length. If the ID does not exist or has already been erased, return -1.
Memory units that are occupied initially are not associated with an allocation ID and cannot be freed by an erase query.
Return an integer array containing one result for every query.

Function
processMemoryQueries(memory: int[], queries: int[][]) → int[]

Examples
Example 1
memory = [0,1,0,0,0,1,1,0,0,0,1,0,0]
queries = [[0,2],[0,1],[0,1],[1,2],[1,4],[0,4]]
return = [2,0,4,1,-1,-1]
The first three allocations use starts 2, 0, and 4, receiving IDs 1, 2, and 3. Erasing ID 2 frees one unit. ID 4 does not exist, and no block of four free units remains for the final allocation.
Example 2
memory = [0,0,0,0]
queries = [[1,1],[0,2],[1,1],[1,1]]
return = [-1,0,2,-1]
The first erase fails because no allocation exists. The allocation then creates ID 1 at index 0. Its first erase frees two units, while the repeated erase returns -1.
Example 3
memory = [1,0,0,0,1,0,0]
queries = [[0,3],[0,2],[1,1],[0,2]]
return = [1,5,3,1]
The first two allocations use starts 1 and 5. Erasing ID 1 frees its three-unit block, so the final allocation returns the newly available leftmost start 1.

Constraints
1 <= memory.length <= 1000
Every value of memory is 0 or 1.
1 <= queries.length <= 1000
Every query contains exactly two integers.
queries[i][0] is 0 or 1.
1 <= queries[i][1] <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

Here's what it reduces to: a linear scan per query plus a hash map from ID to (start, length). With memory length and query count both capped at 1000, an O(n) scan per allocation gives about a million operations. Done. For allocate, walk the array keeping a running count of consecutive zeros. When the count hits x, the start is i - x + 1. Mark those cells as 1, store the ID in the map, increment the ID counter, and return the start. Pitfalls: x can be up to 10^9, so just return -1 when x exceeds the array length. Only bump the ID on success. On erase, delete the map entry so a repeat erase returns -1, and never touch the initial 1s. If you freeze on the live OA, StealthCoder is the hedge, but the logic here is short enough to write from memory.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Leftmost Memory Block Allocator cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as design memory allocator. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass SIG's OA.

SIG reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Leftmost Memory Block Allocator FAQ

How hard is the SIG Leftmost Memory Block Allocator really?+

Easy to medium. There's no clever algorithm. The difficulty is careful state handling: the ID counter, the map of active allocations, and the edge cases. With n and q at 1000, brute force scanning passes comfortably.

What's the trick to this problem?+

Treat it as pure simulation. Keep a dictionary of ID to (start, length). For allocation, scan for the first run of x zeros. For erase, look up the ID, free that range, delete the entry, and return the length.

Do I need a segment tree or heap for the free blocks?+

No. The limits are 1000 cells and 1000 queries, so a linear scan per query is fine. A segment tree would only add bug risk. Save the optimization talk for a follow-up if someone asks.

What edge cases break most solutions?+

Allocation sizes far bigger than the array, up to 10^9. Incrementing the ID on failed allocations. Allowing a second erase of the same ID to succeed. Freeing cells that were initially occupied. Check Example 2 and Example 3 against these.

How do I prepare for this in 48 hours?+

Write the solution once from scratch, then trace all three examples by hand. Practice the running-zero-count scan and the map cleanup on erase. That covers nearly every failure point. Related simulation and design-lite problems follow the same shape.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with SIG.

OA at SIG?
Invisible during screen share
Get it