FastPrepOccupy and Clean Memory by Allocation ID
Problems/Occupy and Clean Memory by Allocation ID

Occupy and Clean Memory by Allocation ID

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Three ZipRecruiter new-grad OA reports describe binary memory, leftmost first-fit allocation, successful allocation IDs that keep increasing, cleanup by exact ID, and -1 for failures. We supplied the [0,k]/[1,id] batch encoding and a function signature as a way to run it.

You are given a binary array memory, where 0 is free and 1 is initially occupied. Process each row in queries:

  • [0, k]: reserve the first k cells of the leftmost free run having length at least k. A successful allocation receives and returns the next positive allocation ID; failure returns -1 and does not consume an ID.
  • [1, id]: free exactly the cells owned by the active allocation id and return its length. Return -1 for an unknown or already-cleaned ID.

Initially occupied cells belong to no allocation and cannot be cleaned.

Function

processMemoryAllocations(memory: int[], queries: int[][]) → int[]

Examples

Example 1

memory = [0,0,1,0,0]queries = [[0,2],[0,1],[1,1],[0,2]]return = [1,2,2,3]

The successful allocations receive IDs 1, 2, and 3; cleaning ID 1 frees two cells.

Example 2

memory = [1,0,0]queries = [[1,1],[0,3],[0,2],[1,1],[1,1],[0,3]]return = [-1,-1,1,2,-1,-1]

Only the two-cell allocation succeeds. Its first cleanup frees two cells; repeated cleanup fails.

Constraints

  • 1 <= memory.length,queries.length <= 2000
  • memory[i] is 0 or 1.
  • Every query has exactly two integers and follows one of the stated forms.

More ZipRecruiter Online Assessment questions

  • Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
  • Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
  • Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
  • Minimum Changes to Draw a YOA · Seen Oct 2024
  • Apply Binary State OperationsOA · Seen Sep 2024
  • Simulate Orchard Rot SpreadOA · Seen Sep 2024
  • Compare Odd- and Even-Index SumsOA · Seen Sep 2024
  • Coordinate Removals with Column GravityOA · Seen Sep 2024
  • Lexicographically Smallest End ReversalOA · Seen Sep 2024
  • Recursively Expanded Shell Command CountsOA · Seen Sep 2024

Similar questions at other companies

  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
  • Process Banking OperationsVercel · OA
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Count House Segments After Sequential DestructionByteDance · OAByteDance interview questions
  • HTTP Request RedirectionAmazon · OA
  • Hungarian Lottery Winner CountsAlpaca · OA
  • Cheating CodemakerJane Street · OAJane Street interview questions
  • Aggregate Paginated Project Run RecordsReplit · OA
  • Maximum Satisfied CustomersAtlassian · OAAtlassian interview questions

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int[] processMemoryAllocations(int[] memory, int[][] queries) {
        // Write your code here.
    }

}
Checking account…