Sliding window flow control

Write codeMedium25 minCisco style

Your task

Simulate sliding-window flow control. A sender must transmit packets 0..total-1 in order but may have at most 'window' packets in flight. It first fills the window with the lowest-numbered packets. Then, for each acknowledgement in 'acks' (processed in order, each ack frees exactly one in-flight slot), the sender immediately sends as many new packets as the window now permits. Return a list parallel to 'acks': for each ack, the list of packet ids newly sent in response (possibly empty). window>=1, total>=0.

Examples

flow_control(window: int, total: int, acks: list[int]) -> list[list[int]]
Example 1
Inputflow_control(2, 5, [0, 1, 2, 3, 4])
Output[[2], [3], [4], [], []]