Reported October 2023
ZipRecruitersimulation

Circular Memory Slot Allocator

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

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

The detail that matters in this ZipRecruiter OA, reported October 2023, is that a Save run is allowed to wrap from the last slot back to slot zero. Example 2 shows it: Save at start 4 with length 2 on 5 slots returns 4 and takes slots 4 and 0. It's a simulation problem on a circular array, with up to 100000 requests against at most 1000 slots. Most candidates will get the happy path working and then lose points on wraparound and on the -1 case that must not mutate anything. If you blank on the cyclic indexing during the live assessment, StealthCoder is the safety net running invisibly on your screen.

The problem

Memory contains totalSlots slots in a circle. Each request is [kind,start,length].
Save scans candidate starts cyclically beginning at start and finds the first run of length consecutive free slots, allowing the run to wrap. Occupy it and return its starting slot, or return -1 without mutation.
Clear frees the guaranteed-occupied circular run beginning at start and returns length.
Return one result per request.

Function
processMemoryRequests(totalSlots: int, requests: String[][]) → int[]

Examples
Example 1
totalSlots = 5
requests = [["Save","1","2"],["Save","1","2"],["Clear","1","2"],["Save","1","2"]]
return = [1,3,2,1]
Allocation, first-fit movement, clearing, and reuse are exercised.
Example 2
totalSlots = 5
requests = [["Save","4","2"]]
return = [4]
A run may wrap from the final slot to zero.

Constraints
1 <= totalSlots <= 1000
1 <= requests.length <= 100000
Every length is between 1 and totalSlots.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that totalSlots is capped at 1000, so brute force per request is fine. Keep a boolean array of occupied slots. For Save, loop candidate starts i from 0 to totalSlots-1, take s = (start + i) % totalSlots, and check that every slot (s + j) % totalSlots for j in 0..length-1 is free. The first s that passes gets marked occupied and returned. If none passes, return -1 and touch nothing. For Clear, free length slots from start using the same modulo and return length. The common pitfall is checking only linear ranges and missing wrapped runs. Another is mutating before you've confirmed the whole run is free. Worst case is roughly 100000 x 1000 x 1000 if you check naively, so break out of the inner loop on the first occupied slot. Use a running count of consecutive free slots to get O(totalSlots) per Save. If the cyclic scan logic goes blank under pressure, StealthCoder can hand you the solution live.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Circular Memory Slot 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

ZipRecruiter reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Circular Memory Slot Allocator FAQ

How hard is the Circular Memory Slot Allocator really?+

It's easy to medium. There's no fancy algorithm, it's careful simulation. The difficulty is modulo indexing, first-fit order starting from the given start, and not mutating on failure. If you write it cleanly and test the wrap example, you're most of the way there.

What's the trick for the wraparound?+

Never think in linear ranges. Index every slot as (s + j) % totalSlots. That handles runs crossing the end automatically. Example 2 is your test: start 4, length 2, on 5 slots occupies slots 4 and 0 and returns 4.

Will brute force pass the constraints?+

Probably, if you're careful. Slots are at most 1000 and requests up to 100000. Checking each candidate start with early exit on the first occupied slot is usually fast enough. A sliding count of consecutive free slots makes each Save O(totalSlots) and removes the doubt.

What edge cases should I test before submitting?+

Test a Save that fails and returns -1 without changing state. Test length equal to totalSlots on an empty memory and on a partly full one. Test a wrapped Clear. Test repeated Saves from the same start, which Example 1 shows moving to the next free run.

How do I prepare in 48 hours?+

Write this one from scratch twice with a boolean array and modulo indexing. Then do two or three other circular-array simulation problems. Focus on first-fit scan order and the no-mutation-on-failure rule. Don't waste time on advanced data structures, the constraints don't need them.

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

OA at ZipRecruiter?
Invisible during screen share
Get it