Katkat

Design a packet reassembler API

BloombergSoftware Engineer · Technical Screen

Last updated

This question evaluates API design, stream-oriented buffer management, stateful packet assembly, input validation, concurrency control, testing strategy, and time/space complexity reasoning.

Design a PacketAssembler API that accepts streaming fragments and emits a completed payload once enough bytes have been received. Example interaction: packetit(0x04, 'a', 'b', 'c') -> no output (header 4 indicates total size; only 3 bytes arrived); packetit('d') -> 'abcd' (completes the prior packet). Specify the class/method signatures, state management (buffering and expected size), behavior for multiple consecutive packets, handling of invalid headers or oversized input, when/if state resets after emission, and thread-safety considerations. Provide tests and analyze time and space complexity.