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
Deadlock Implementation
00:00
5 left

Deadlock Implementation

MediumPython

Problem

HPE Ezmeral workloads may have processes holding resource instances while waiting for additional instances. Given a snapshot of resource availability, allocations, and outstanding requests, return every process that can never complete because of a deadlock.

Use the standard deadlock-detection algorithm: assume a process can finish when all of its outstanding requests can be satisfied by the currently available resources. When it finishes, release its allocated resources and continue checking other processes. Processes that remain unfinished are deadlocked.

Formal Specification

Implement detect_deadlock(available, allocation, requests).

  • available is an integer array of length R, where available[j] is the number of currently free instances of resource type j.
  • allocation is an integer matrix with P rows and R columns. allocation[i][j] is held by process i.
  • requests is an integer matrix with the same dimensions. requests[i][j] is the additional number of instances process i needs to finish.
  • Return a sorted integer array containing the indices of all deadlocked processes. Return [] if no deadlock exists.

Constraints

  • 1 <= P, R <= 500
  • available has length R
  • allocation and requests are P x R matrices
  • All resource counts are non-negative integers
  • The returned process indices must be sorted

Function Signature

def detect_deadlock(available, allocation, requests):
Interviewer

Your question is Deadlock Implementation. 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.