Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Memory Allocation for Streaming Pipelines
00:00
5 left

Memory Allocation for Streaming Pipelines

HardPython

Problem

Write a function to optimize the memory allocation for a streaming data pipeline. Given memory requests as [start, end, blocks], where end is exclusive, assign reusable integer block IDs to every request. Requests whose lifetimes overlap must not share blocks. Return allocations in input order and the minimum peak number of blocks required. Use def optimize_memory_allocation(requests):, with output {"allocations": List[List[int]], "peak_blocks": int}. Requests may be unsorted, and a request ending at time t may share blocks with one starting at t].

Constraints

  • 1 <= len(requests) <= 500
  • Each request has the form [start, end, blocks]
  • 0 <= start < end <= 10^9
  • 1 <= blocks <= 10^5
  • The total number of requested blocks can be large
  • Block IDs must be nonnegative integers and allocations must be disjoint for overlapping lifetimes

Function Signature

def optimize_memory_allocation(requests):
Interviewer

Your question is Memory Allocation for Streaming Pipelines. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.