Code Room
CodingMediumcod-g1142
Subject Networking protocolsLevel Mid–Senior~25 minCommon in Networking & APIs · Algorithms & data structures interviewsIndustries Software development, Telecom

Question

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.

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.