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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
Bit masks
State machine
Encoding
Input validation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 == 0 means ASCII (n...

Submit Your Answer
Markdown supported