Validate That a WhatsApp Message Payload Is Well-Formed UTF-8
Last updated: November 29, 2026
Quick Overview
Given a list of integers where each holds one byte (its low 8 bits), determine whether the sequence is a valid UTF-8 encoding of 1- to 4-byte characters.
Meta
November 29, 20260
0
0 solved
Given a list of integers where each holds one byte (its low 8 bits), determine whether the sequence is a valid UTF-8 encoding of 1- to 4-byte characters.
A Meta screen question that mixes bit masks with a small state machine, motivated by validating message payloads before rendering them. The interviewer checks that you read the leading-byte patterns correctly and track how many continuation bytes are still owed.
What the Interviewer Expects
- State the four leading-byte patterns and the 10xxxxxx continuation pattern
- Track remaining continuation bytes as state
- Reject truncated sequences at the end
- Mask each integer to its low 8 bits
- Mention stricter checks like overlong encodings and surrogates
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Also reject overlong encodings and code points above U+10FFFF.
- How would you validate a stream arriving in arbitrary chunks?
- How would you count characters instead of just validating?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of ints; only the low 8 bits of each matter. Valid characters: 0xxxxxxx; 110xxxxx 10xxxxxx; 1110xxxx plus two continuations; 11110xxx plus three. Output: True if the whole sequence...
High-Level Design
The decoder is a two-state machine with a counter need of continuation bytes still expected.
- When
need == 0, the byte must be a leading byte. Inspect the high bits:b >> 7 == 0means ASCII (n...