Banker's algorithm safety check
Your task
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.
Examples
bankers_safe(available: int, alloc: list[int], maxneed: list[int]) -> list[int]Example 1
Input
bankers_safe(2, [1, 2], [4, 3])Output
[1, 0]