Design a packet reassembler API
Company: Bloomberg
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Technical Screen
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.
Quick Answer: This question evaluates API design, stream-oriented buffer management, stateful packet assembly, input validation, concurrency control, testing strategy, and time/space complexity reasoning.