Length-prefixed deframing
Deframe a byte stream of length-prefixed messages. The input is a list of byte values. Each message is a single length-prefix byte N followed by exactly N payload bytes. Return a list of payloads (each a list of ints) in order. If the stream ends in the middle of a frame (fewer than N payload bytes remain), discard that trailing incomplete frame. A length byte of 0 yields an empty payload.
Implement
deframe(stream: list[int]) → list[list[int]]Examples
in
[[3,1,2,3,2,9,8]]out[[1,2,3],[9,8]]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 20 min
solution.py
InputExpectedGot
[[3,1,2,3,2,9,8]][[1,2,3],[9,8]]not run yetsample