FastPrepAligned Free-List Memory Allocator
Problems/Aligned Free-List Memory Allocator

Aligned Free-List Memory Allocator

Hudson River Trading logoHudson River Trading● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Hudson River Trading intern onsite interview. The report describes a fixed-size memory allocator that keeps a linked-list free list. It then asks about alignment and a 9-byte allocation. It does not give the outside API, where blocks are placed, what failure returns, what free guarantees, or the shape of the input. Our version is about 90% the same as the reported question.

Implement an allocator for one fixed-size memory region. The region contains totalBytes bytes, begins at address 0, and is divided into blocks of alignment bytes.

You are given equal-length arrays operations and values. Process them in order:

  • allocate requests values[i] bytes. Round the request up to a whole number of alignment blocks, then reserve the first free contiguous range large enough to hold it. Return that range's starting address, or -1 when no free range is large enough.
  • free releases the live allocation whose starting address is values[i]. Every free operation is guaranteed to reference a currently live allocation.

Return the addresses produced by allocate operations, in encounter order. Maintain free memory as an address-ordered linked list of maximal free ranges. Split a range when allocating and coalesce adjacent ranges when freeing.

Function

runAllocator(totalBytes: int, alignment: int, operations: String[], values: int[]) → int[]

Examples

Example 1

totalBytes = 32alignment = 8operations = ["allocate","allocate","free","allocate"]values = [9,8,0,16]return = [0,16,0]

The 9-byte request rounds up to 16 bytes and starts at 0. The 8-byte request starts at 16. Freeing address 0 makes the first 16 bytes available again, so the last request returns 0.

Example 2

totalBytes = 24alignment = 8operations = ["allocate","allocate","allocate","free","allocate"]values = [8,16,8,0,8]return = [0,8,-1,0]

The first two allocations fill the region. The third request fails. After address 0 is freed, one block is available there and the final request succeeds.

Constraints

  • 1 <= alignment <= 1024, and alignment is a power of two.
  • alignment <= totalBytes <= 1000000.
  • totalBytes is divisible by alignment.
  • 0 <= operations.length <= 200000.
  • operations.length == values.length.
  • Every operation is allocate or free.
  • For allocate, 1 <= values[i] <= totalBytes.
  • For free, values[i] is the starting address of a live allocation.

More Hudson River Trading interview questions

  • Tiered Expiring Item StorePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Read a File from Distributed ChunksONSITE INTERVIEW · Seen Aug 2026
  • Best Expected Result in Simplified BlackjackONSITE INTERVIEW · Seen Apr 2025
  • Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
  • Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
  • Count Palindrome Addition ChoicesOA · Seen Nov 2026
  • Tilting Maze BallPHONE SCREEN · Seen Oct 2026
  • Count Multiples of Three with Two SevensOA · Seen Oct 2026
  • Recursively Expanded Shell Command CountsOA · Seen Oct 2026
  • Rotate Matrix Regions Around the DiagonalsOA · Seen Oct 2026

Similar questions at other companies

  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • LRU CacheAMD · ONSITE INTERVIEWAMD interview questions
  • Least Recently Used CacheByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • LRU Cache with Hit and Miss CountersLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Least Recently Used CacheGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • LRU CacheIntuit · ONSITE INTERVIEWIntuit interview questions
  • LRU CacheOracle · ONSITE INTERVIEWOracle interview questions

Hudson River Trading interview experiences

  • Hudson River Trading Data Science Interviews: 2 Experiences
  • Hudson River Trading interviews · 2021
  • Hudson River Trading OA · 2021
  • Hudson River Trading interviews · 2022
  • Hudson River Trading OA · 2022
  • Hudson River Trading interviews · 2023
All Hudson River Trading interview questionsSee Hudson River Trading hiring insights
Saved
class Solution {
    public int[] runAllocator(int totalBytes, int alignment, String[] operations, int[] values) {
      // write your code here
    }
}
Checking account…