Sliding window flow control
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.
Implement
flow_control(window: int, total: int, acks: list[int]) → list[list[int]]Examples
in
[2,5,[0,1,2,3,4]]out[[2],[3],[4],[],[]]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 25 min
solution.py
InputExpectedGot
[2,5,[0,1,2,3,4]][[2],[3],[4],[],[]]not run yetsample