Code Room
CodingHardcod-g1131
Subject ConcurrencyLevel Senior–Staff~35 minCommon in Concurrency interviewsIndustries Software development, Technology

Question

Implement the Banker's algorithm safety check for a single resource type. There are N processes. available is the count of free units. alloc[i] is units currently held by process i. maxneed[i] is process i's maximum total demand. The system is SAFE if there exists an ordering in which every process can acquire its remaining need (maxneed[i] - alloc[i]), run to completion, and release everything, never blocking. Use the standard greedy: repeatedly pick any process whose remaining need ≤ work; to keep the result deterministic, always pick the LOWEST-indexed such process. Return the safe sequence (list of process indices) if safe, or an empty list if no safe sequence exists.

Implement
bankers_safe(available: int, alloc: list[int], maxneed: list[int]) → list[int]
Examples
in[2,[1,2],[4,3]]out[1,0]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.