FastPrepReusable Number Allocator
Problems/Reusable Number Allocator

Reusable Number Allocator

Dropbox logoDropbox● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes handing out numbers from 0 through N - 1 and releasing them so they can be used again. It does not say which number to pick or what happens when none are left. This version picks the smallest available number and returns -1 when none are left. Our version is about 89% the same as the reported question.

Implement a reusable allocator for the integers from 0 through n - 1.

The allocator starts with every number available. Process the parallel arrays operations and values from left to right:

  • assign returns and reserves the smallest currently available number. If no number is available, it returns -1. Its corresponding entry in values is -1.
  • release makes values[i] available again. Every release is guaranteed to name a number that is currently assigned. A release produces no output.

Return the results of all assign operations in operation order.

Function

runNumberAllocator(n: int, operations: String[], values: int[]) → int[]

Examples

Example 1

n = 3operations = ["assign","assign","release","assign","assign"]values = [-1,-1,0,-1,-1]return = [0,1,0,2]

The first two assignments reserve 0 and 1. Releasing 0 makes it the smallest available number again, so the next assignment reuses it before assigning 2.

Example 2

n = 2operations = ["assign","assign","assign","release","assign"]values = [-1,-1,-1,1,-1]return = [0,1,-1,1]

After 0 and 1 are assigned, the allocator is exhausted and returns -1. Releasing 1 lets the final assignment return 1.

Constraints

  • 1 <= n <= 10^6
  • 1 <= operations.length <= 2 * 10^5
  • values.length == operations.length
  • Each operation is exactly assign or release.
  • For assign, the corresponding value is -1.
  • For release, 0 <= values[i] < n and that number is currently assigned.

More Dropbox interview questions

  • Find Duplicate Files by ContentONSITE INTERVIEW · Seen Feb 2021
  • Remove Redundant Directory GrantsPHONE SCREEN · Seen Feb 2021

Similar questions at other companies

  • Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
  • Delayed Job SchedulerWalmart Labs · ONSITE INTERVIEW
  • Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
  • Notification Deduplication WindowGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Implement a Min-Priority QueueAmazon · ONSITE INTERVIEW
  • Helpdesk Ticket ProcessingThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Execute Tasks by PrioritySnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Priority Job Scheduler with CooldownsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Order Matching EngineJane Street · ONSITE INTERVIEWJane Street interview questions
  • Trip Booking with the Earliest Free DriverRippling · ONSITE INTERVIEWRippling interview questions
All Dropbox interview questionsSee Dropbox hiring insights
Saved
class Solution {
    public int[] runNumberAllocator(int n, String[] operations, int[] values) {
        // Write your code here.
    }
}
Checking account…