A four-byte emoji split across three tokens will raise on every naive decode, and the fix is a buffer that holds the incomplete tail. The decoder in a dozen lines, the exception field that tells you exactly where to cut, and what to do when the stream ends mid-character.
Tokens arrive as byte fragments and a character can span several. Write the decoder that streams text correctly.
A four-byte emoji split across three tokens will raise on every naive decode, and the fix is a buffer that holds the incomplete tail. The decoder in a dozen lines, the exception field that tells you exactly where to cut, and what to do when the stream ends mid-character.
Updated Sep 2026 · Grounded in real AI infrastructure interview loops and written to a senior-engineer editorial bar, with every number worked and every diagram hand-built.
The concepts behind this question
Ranked by how closely each one overlaps this question's topic, so the first card is the thing to read if the answer above moved too fast.
Scored on buffering the incomplete tail rather than decoding each piece, on using the decode error's start offset rather than guessing the boundary, and on a flush that handles a truncated stream.
No comments yet — be the first to share your approach.
