Code RoomBanker's algorithm safety check
HardPrep Room Coding #302

Banker's algorithm safety check

CodingConcurrencySenior–Staff~35 min

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.

0:00 of about 35 min
InputExpectedGot
[2,[1,2],[4,3]][1,0]not run yetsample