Code RoomFind peak flight data
EasyPrep Room Coding #4816

Find peak flight data

CodingNetworking & APIsEntry–Mid~12 min

A link monitor replays the trace a sender recorded on one connection and reports how much data sat in flight at the worst moment. Every line of trace is either send:N, meaning the sender put N more bytes on the wire, or ack:K, meaning the receiver has confirmed the first K bytes of the stream counted from the moment the connection opened. Acknowledgements are cumulative, so one whose number is not greater than the highest number already accepted is a duplicate and changes nothing. One whose number is greater than the total bytes sent so far cannot be true and is ignored completely. After every line the unacknowledged amount is the total sent minus the highest accepted acknowledgement. Return the largest unacknowledged amount this connection ever held, or 0 for an empty trace.

Implement
peak_unacked_bytes(trace: list[str]) → int
Examples
in[["send:100","send:200","ack:100","send:50"]]out300
in[["send:10","ack:40","send:100","ack:40"]]out110
in[["send:500","ack:500"]]out500
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 12 min
InputExpectedGot
[["send:100","send:200","ack:100","send:50"]]300not run yetsample
[["send:10","ack:40","send:100","ack:40"]]110not run yetsample
[["send:500","ack:500"]]500not run yetsample