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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Calculate Leaks and Peak Allocated Bytes
00:00
5 left

Calculate Leaks and Peak Allocated Bytes

MediumPython

Problem

Explain memory allocation and how you would debug memory-related issues in a system program.

Implement analyze_memory(events) to simulate allocation and release events. Each event is an array representing either ['alloc', block_id, size] or ['free', block_id]; return a map containing invalid free count, leaked block count, leaked bytes, and peak allocated bytes.

Constraints

  • 1 <= events.length <= 10^5
  • Each event is either ['alloc', block_id, size] or ['free', block_id]
  • block_id is a non-empty string
  • 1 <= size <= 10^9
  • An allocation identifier is not allocated while it is already active
  • Process events in their given order

Function Signature

def analyze_memory(events):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

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.